Skip to content

Commit c95d457

Browse files
committed
Refactor track.js clip/transition dropping to queue up JSON changes until the end, so all Angular scope changes happen more quickly. This prevents some strange issues like clicking on the timeline while a mass update happens, breaking the current track target.
1 parent d3c1b36 commit c95d457

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/timeline/js/directives/track.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ App.directive("tlTrack", function ($timeout) {
6666
var ui_selected = $(".ui-selected");
6767
var selected_item_count = ui_selected.length;
6868

69+
// Arrays to collect updates for batch processing
70+
var clip_updates = [];
71+
var transition_updates = [];
72+
6973
// Get uuid to group all these updates as a single transaction
7074
var tid = uuidv4();
7175
var drop_track_num = -1;
@@ -132,18 +136,26 @@ App.directive("tlTrack", function ($timeout) {
132136
// Keep track of dropped clips (we'll check for missing transitions in a sec)
133137
dropped_clips.push(item_data);
134138

135-
// Determine if this is the last iteration
136-
var needs_refresh = (index === selected_item_count - 1);
137-
138-
// update clip in Qt (very important =)
139-
if (scope.Qt && item_type === "clip") {
140-
timeline.update_clip_data(JSON.stringify(item_data), true, true, !needs_refresh, tid);
141-
} else if (scope.Qt && item_type === "transition") {
142-
timeline.update_transition_data(JSON.stringify(item_data), true, !needs_refresh, tid);
139+
// Collect updates for later batch processing
140+
if (item_type === "clip") {
141+
clip_updates.push(item_data);
142+
} else if (item_type === "transition") {
143+
transition_updates.push(item_data);
143144
}
145+
}
146+
});
144147

148+
// Now fire all the Qt updates after all scope.$apply calls
149+
// Update clips in Qt
150+
clip_updates.forEach(function(item_data, index) {
151+
var needs_refresh = (index === clip_updates.length - 1);
152+
timeline.update_clip_data(JSON.stringify(item_data), true, true, !needs_refresh, tid);
153+
});
145154

146-
}
155+
// Update transitions in Qt
156+
transition_updates.forEach(function(item_data, index) {
157+
var needs_refresh = (index === transition_updates.length - 1);
158+
timeline.update_transition_data(JSON.stringify(item_data), true, !needs_refresh, tid);
147159
});
148160

149161
// Add missing transitions (if any)

0 commit comments

Comments
 (0)