Skip to content

Commit 12ff3ff

Browse files
authored
Merge pull request #13 from PlkMarudny/zoom-to-fit-selection
feat: use multiple clips for 'zoom to selection' ('z')
2 parents e9286c2 + b847141 commit 12ff3ff

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

‎app.js‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,17 +1219,20 @@ function zoomToFit() {
12191219
setZoom(w / span);
12201220
els.timelineScroll.scrollLeft = 0;
12211221
}
1222-
/* Zoom so the primary selected clip fills 90% of the timeline width and is centered. */
1222+
/* Zoom so the selection fills 90% of the timeline width and is centered.
1223+
One clip → that clip; multiple → the time range covering all of them. */
12231224
function zoomToSelection() {
1224-
const c = getClip(state.selId) || selectedClips()[0];
1225-
if (!c) { toast("Select a clip to zoom to"); return; }
1225+
const clips = selectedClips();
1226+
if (!clips.length) { toast("Select a clip to zoom to"); return; }
1227+
const t0 = Math.min(...clips.map((c) => c.start));
1228+
const t1 = Math.max(...clips.map((c) => c.start + c.duration));
1229+
const dur = Math.max(t1 - t0, MIN_DUR);
12261230
const w = els.timelineScroll.clientWidth || 800;
1227-
const dur = Math.max(c.duration, MIN_DUR);
12281231
const pps = clamp((0.9 * w) / dur, ZOOM_MIN, ZOOM_MAX);
12291232
state.pps = pps;
12301233
els.zoomSlider.value = pps;
12311234
rebuildClips();
1232-
const center = c.start + c.duration / 2;
1235+
const center = (t0 + t1) / 2;
12331236
const maxScroll = Math.max(0, contentWidth() - w);
12341237
els.timelineScroll.scrollLeft = clamp(center * pps - w / 2, 0, maxScroll);
12351238
}

‎index.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ <h2>Keyboard shortcuts</h2>
163163
<tr><td><kbd>M</kbd></td><td>Add / remove marker at playhead (tap on the beat while playing)</td></tr>
164164
<tr><td><kbd>N</kbd></td><td>Toggle snapping</td></tr>
165165
<tr><td><kbd>+</kbd> / <kbd>-</kbd></td><td>Zoom timeline</td></tr>
166-
<tr><td><kbd>Z</kbd></td><td>Zoom to selected clip</td></tr>
166+
<tr><td><kbd>Z</kbd></td><td>Zoom to selected clip(s)</td></tr>
167167
<tr><td><kbd>⇧</kbd>+<kbd>Z</kbd></td><td>Zoom timeline to fit</td></tr>
168168
<tr><td><kbd>Ctrl</kbd>+<kbd>Z</kbd> / <kbd>Ctrl</kbd>+<kbd>⇧</kbd>+<kbd>Z</kbd></td><td>Undo / redo</td></tr>
169169
<tr><td><kbd>Ctrl</kbd>+wheel</td><td>Zoom timeline at cursor</td></tr>

0 commit comments

Comments
 (0)