perf: reduce editor redraw sorting overhead
This commit is contained in:
@@ -81,6 +81,16 @@ function findSegmentIndexById(segments = [], segmentId) {
|
|||||||
function findSegmentById(segments = [], segmentId) {
|
function findSegmentById(segments = [], segmentId) {
|
||||||
return (segments || []).find((seg) => seg.id === segmentId);
|
return (segments || []).find((seg) => seg.id === segmentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function partitionSegmentsBySelection(segments = [], selectedIdSet) {
|
||||||
|
const unselected = [];
|
||||||
|
const selected = [];
|
||||||
|
for (const seg of segments || []) {
|
||||||
|
if (selectedIdSet.has(seg.id)) selected.push(seg);
|
||||||
|
else unselected.push(seg);
|
||||||
|
}
|
||||||
|
return unselected.concat(selected);
|
||||||
|
}
|
||||||
|
|
||||||
function hideWidget(w) {
|
function hideWidget(w) {
|
||||||
if (!w) return;
|
if (!w) return;
|
||||||
@@ -6055,23 +6065,9 @@ class TimelineEditor {
|
|||||||
if (this._previewSegments && previewIsMotion) renderMotionSegments = this._previewSegments;
|
if (this._previewSegments && previewIsMotion) renderMotionSegments = this._previewSegments;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sortedSegments = [...renderSegments].sort((a, b) => {
|
const sortedSegments = partitionSegmentsBySelection(renderSegments, selectedIdSet);
|
||||||
const aSel = selectedIdSet.has(a.id) ? 1 : 0;
|
const sortedMotionSegments = partitionSegmentsBySelection(renderMotionSegments, selectedIdSet);
|
||||||
const bSel = selectedIdSet.has(b.id) ? 1 : 0;
|
const sortedAudioSegments = partitionSegmentsBySelection(renderAudioSegments, selectedIdSet);
|
||||||
return aSel - bSel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const sortedMotionSegments = [...renderMotionSegments].sort((a, b) => {
|
|
||||||
const aSel = selectedIdSet.has(a.id) ? 1 : 0;
|
|
||||||
const bSel = selectedIdSet.has(b.id) ? 1 : 0;
|
|
||||||
return aSel - bSel;
|
|
||||||
});
|
|
||||||
|
|
||||||
const sortedAudioSegments = [...renderAudioSegments].sort((a, b) => {
|
|
||||||
const aSel = selectedIdSet.has(a.id) ? 1 : 0;
|
|
||||||
const bSel = selectedIdSet.has(b.id) ? 1 : 0;
|
|
||||||
return aSel - bSel;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (this.retakeMode) {
|
if (this.retakeMode) {
|
||||||
// Draw Retake Mode Filmstrip and Overlay
|
// Draw Retake Mode Filmstrip and Overlay
|
||||||
@@ -7643,16 +7639,17 @@ class TimelineEditor {
|
|||||||
clickedId = targetArray[clickedIdx].id;
|
clickedId = targetArray[clickedIdx].id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clickedId) {
|
if (clickedId) {
|
||||||
if (isCtrl) {
|
const selectedIdSet = new Set(this.selectedSegmentIds || []);
|
||||||
const sibId = clickedId.endsWith("_v") ? clickedId.slice(0, -2) + "_a" : (clickedId.endsWith("_a") ? clickedId.slice(0, -2) + "_v" : null);
|
if (isCtrl) {
|
||||||
const isSelected = this.selectedSegmentIds.includes(clickedId);
|
const sibId = clickedId.endsWith("_v") ? clickedId.slice(0, -2) + "_a" : (clickedId.endsWith("_a") ? clickedId.slice(0, -2) + "_v" : null);
|
||||||
if (isSelected) {
|
const isSelected = selectedIdSet.has(clickedId);
|
||||||
this.selectedSegmentIds = this.selectedSegmentIds.filter(id => id !== clickedId && id !== sibId);
|
if (isSelected) {
|
||||||
} else {
|
this.selectedSegmentIds = this.selectedSegmentIds.filter(id => id !== clickedId && id !== sibId);
|
||||||
if (!this.selectedSegmentIds.includes(clickedId)) this.selectedSegmentIds.push(clickedId);
|
} else {
|
||||||
if (sibId && !this.selectedSegmentIds.includes(sibId)) this.selectedSegmentIds.push(sibId);
|
if (!selectedIdSet.has(clickedId)) this.selectedSegmentIds.push(clickedId);
|
||||||
}
|
if (sibId && !selectedIdSet.has(sibId)) this.selectedSegmentIds.push(sibId);
|
||||||
|
}
|
||||||
|
|
||||||
if (this.selectedSegmentIds.length > 0) {
|
if (this.selectedSegmentIds.length > 0) {
|
||||||
this.selectionType = clickedTrack;
|
this.selectionType = clickedTrack;
|
||||||
@@ -7661,16 +7658,16 @@ class TimelineEditor {
|
|||||||
this.selectedIndex = -1;
|
this.selectedIndex = -1;
|
||||||
}
|
}
|
||||||
this._multiDragClickPendingDeselect = null;
|
this._multiDragClickPendingDeselect = null;
|
||||||
} else {
|
} else {
|
||||||
if (this.selectedSegmentIds.includes(clickedId)) {
|
if (selectedIdSet.has(clickedId)) {
|
||||||
this._multiDragClickPendingDeselect = clickedId;
|
this._multiDragClickPendingDeselect = clickedId;
|
||||||
} else {
|
} else {
|
||||||
this.selectedSegmentIds = [clickedId];
|
this.selectedSegmentIds = [clickedId];
|
||||||
const sibId = clickedId.endsWith("_v") ? clickedId.slice(0, -2) + "_a" : (clickedId.endsWith("_a") ? clickedId.slice(0, -2) + "_v" : null);
|
const sibId = clickedId.endsWith("_v") ? clickedId.slice(0, -2) + "_a" : (clickedId.endsWith("_a") ? clickedId.slice(0, -2) + "_v" : null);
|
||||||
if (sibId && !this.selectedSegmentIds.includes(sibId)) this.selectedSegmentIds.push(sibId);
|
if (sibId && !selectedIdSet.has(sibId)) this.selectedSegmentIds.push(sibId);
|
||||||
this.selectionType = clickedTrack;
|
this.selectionType = clickedTrack;
|
||||||
this.selectedIndex = clickedIdx;
|
this.selectedIndex = clickedIdx;
|
||||||
this._multiDragClickPendingDeselect = null;
|
this._multiDragClickPendingDeselect = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user