Skip to content

Commit ca6ead2

Browse files
committed
add range selection for zoom
1 parent 2a153d0 commit ca6ead2

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

apps/desktop/src/routes/editor/Timeline/ZoomTrack.tsx

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -314,29 +314,42 @@ export function ZoomTrack(props: {
314314

315315
const currentSelection = editorState.timeline.selection;
316316
const segmentIndex = i();
317+
const isMultiSelect = e.ctrlKey || e.metaKey;
318+
const isRangeSelect = e.shiftKey;
319+
320+
if (isRangeSelect && currentSelection?.type === "zoom") {
321+
// Range selection: select from last selected to current
322+
const existingIndices = currentSelection.indices;
323+
const lastIndex =
324+
existingIndices[existingIndices.length - 1];
325+
const start = Math.min(lastIndex, segmentIndex);
326+
const end = Math.max(lastIndex, segmentIndex);
327+
const rangeIndices: number[] = [];
328+
for (let idx = start; idx <= end; idx++) {
329+
rangeIndices.push(idx);
330+
}
317331

318-
// Handle multi-selection with Ctrl/Cmd+click
319-
if (e.ctrlKey || e.metaKey) {
332+
setEditorState("timeline", "selection", {
333+
type: "zoom",
334+
indices: rangeIndices,
335+
});
336+
} else if (isMultiSelect) {
337+
// Handle multi-selection with Ctrl/Cmd+click
320338
if (currentSelection?.type === "zoom") {
321-
// Normalize to indices[] from either indices[] or legacy index
322-
const baseIndices =
323-
"indices" in currentSelection &&
324-
Array.isArray(currentSelection.indices)
325-
? currentSelection.indices
326-
: "index" in currentSelection &&
327-
typeof currentSelection.index === "number"
328-
? [currentSelection.index]
329-
: [];
330-
339+
const baseIndices = currentSelection.indices;
331340
const exists = baseIndices.includes(segmentIndex);
332341
const newIndices = exists
333342
? baseIndices.filter((idx) => idx !== segmentIndex)
334343
: [...baseIndices, segmentIndex];
335344

336-
setEditorState("timeline", "selection", {
337-
type: "zoom",
338-
indices: newIndices,
339-
});
345+
if (newIndices.length > 0) {
346+
setEditorState("timeline", "selection", {
347+
type: "zoom",
348+
indices: newIndices,
349+
});
350+
} else {
351+
setEditorState("timeline", "selection", null);
352+
}
340353
} else {
341354
// Start new multi-selection
342355
setEditorState("timeline", "selection", {
@@ -345,6 +358,7 @@ export function ZoomTrack(props: {
345358
});
346359
}
347360
} else {
361+
// Normal single selection
348362
setEditorState("timeline", "selection", {
349363
type: "zoom",
350364
indices: [segmentIndex],

0 commit comments

Comments
 (0)