Skip to content

Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.

Editor: ripple delete removes a clip and closes the time it took

Bowen Xueb8359e2f67c4
diff --git a/web/editor_actions.js b/web/editor_actions.js
index 4c03c0e..4e8bbb2 100644
--- a/web/editor_actions.js
+++ b/web/editor_actions.js
@@ -3,6 +3,7 @@
// splitAt (record, ids, frame, {by}) <-> Split (B)
// trimAt (record, ids, frame, edge, {by}) <-> Trim before/after (Q/W)
// removeParts (record, ids) <-> Delete / Backspace / Cut
+// rippleRemoveParts (record, ids) <-> Ripple delete (Shift+Delete / Shift+Backspace)
// removeGaps (record, gap|null) <-> Remove gaps / Delete a gap
// duplicateParts (record, ids) <-> Duplicate (D)
// copyTo (record, ids, at) <-> Copy + Paste at the playhead
@@ -12,7 +13,7 @@
// an explicit track must be an original lane of the group. No snapping here.
// A cut by the user (the default) takes the block from the agent; by: 'agent' keeps its mark.
import * as model from './editor_model.js';
-import {assertUnlocked} from './editor_text_model.js';
+import {assertUnlocked, isText} from './editor_text_model.js';
import {copyContent, pasteContent, playheadTargets, removableGaps} from './editor_room.js';
const end = clip => clip.start + clip.frames;
@@ -49,6 +50,28 @@ export function trimAt(record, ids, frame, edge, {by = 'user'} = {}) {
export function removeParts(record, ids) {
return edit(() => model.remove(record, linkedIds(record, ids)));
}
+// Delete the parts, then close only the time they took (a gap that was already there stays), right to left
+// so earlier spans keep their frames. A span that cannot close stays open and is listed in `skipped`.
+// Text and subtitles only lie over the picture, so deleting them closes nothing.
+export function rippleRemoveParts(record, ids) {
+ ids = linkedIds(record, ids);
+ const taken = record.tracks.flatMap(track => track.clips).filter(clip => ids.includes(clip.id) && !isText(clip))
+ .sort((a, b) => a.start - b.start), spans = [];
+ for (const clip of taken) {
+ const last = spans.at(-1);
+ if (last && clip.start <= last.end) last.end = Math.max(last.end, end(clip));
+ else spans.push({start: clip.start, end: end(clip)});
+ }
+ let next = removeParts(record, ids); const skipped = [];
+ for (const span of spans.reverse()) {
+ try { next = edit(() => model.closeSpan(next, span.end, span.end - span.start)); }
+ catch (error) {
+ if (!(error instanceof model.EditError) || !['busy', 'locked', 'overlap'].includes(error.code)) throw error;
+ skipped.push({start: span.start, track: error.track, code: error.code});
+ }
+ }
+ return {record: next, closed: spans.length - skipped.length, skipped: skipped.reverse()};
+}
export function removeGaps(record, gap) {
if (gap !== null) {
check(gap && record.tracks.some(track => track.id === gap.track));
diff --git a/web/editor_menu.js b/web/editor_menu.js
index 6fadae2..7bc6b84 100644
--- a/web/editor_menu.js
+++ b/web/editor_menu.js
@@ -41,6 +41,7 @@ export function menuItems(context) {
command('x', t('Cut', '剪切'), `${modifier}+X`, copyable && !generating),
command('d', t('Duplicate', '创建副本'), `${modifier}+D`, copyable),
command('delete', t('Delete', '删除'), 'Delete', !generating),
+ command('ripple', t('Ripple delete', '波纹删除'), 'Shift+Delete', !generating),
command('b', t('Split', '剪开'), `${modifier}+B`, !splitBusy && canSplit, 'split'),
] : [
command('v', t('Paste', '粘贴'), `${modifier}+V`, commands.canPaste()),
diff --git a/web/editor_model.js b/web/editor_model.js
index d4a70d8..0678e2f 100644
--- a/web/editor_model.js
+++ b/web/editor_model.js
@@ -654,15 +654,20 @@ export function closeGap(record, trackId, frame) {
check(whole(frame), 'range');
const gap = gaps(record, trackId).find(item => frame >= item.start && frame < item.start + item.frames);
if (!gap) return parse(record);
- const from = gap.start + gap.frames;
+ return closeSpan(record, gap.start + gap.frames, gap.frames);
+}
+// Move everything that starts at `from` or later `frames` earlier on every track, the way a closed gap does.
+// Content that would land on a part that stays, a locked track or a generating part refuses the whole move.
+export function closeSpan(record, from, frames) {
+ check(whole(from) && whole(frames, 1) && frames <= from, 'range');
for (const track of record.tracks) {
const moving = track.clips.filter(clip => clip.start >= from), fixed = track.clips.filter(clip => clip.start < from);
const code = moving.some(clip => ['queued', 'running'].includes(clip.pending)) ? 'busy'
: moving.length && track.locked ? 'locked'
- : moving.some(clip => fixed.some(other => overlaps(other, clip.start - gap.frames, clip.frames))) ? 'overlap' : null;
+ : moving.some(clip => fixed.some(other => overlaps(other, clip.start - frames, clip.frames))) ? 'overlap' : null;
if (code) { const error = new EditError(code); error.track = track.id; throw error; }
}
- const next = copy(record); shift(next, from, -gap.frames); return finish(next);
+ const next = copy(record); shift(next, from, -frames); return finish(next);
}
export function setVolume(record, id, volume) {
const next = copy(record), track = trackOf(next, id); check(track, 'missing'); check(track.kind === 'audio', 'track');
diff --git a/web/editor_select.js b/web/editor_select.js
index 764d0a2..5665ddf 100644
--- a/web/editor_select.js
+++ b/web/editor_select.js
@@ -82,6 +82,8 @@ export function createSelectionActions({state, t = en => en, actions = {}, clipb
}
function run(key) {
try {
+ // Ripple delete only differs for parts; a selected gap or range is deleted as with Delete.
+ if (key === 'ripple' && state.selection?.kind !== 'clip') key = 'delete';
const ids = selectedIds(state.record, state.selection);
if (key === 'a') { state.select(selection(unlockedIds(state.record))); return {ok: true}; }
if (['b', 'q', 'w'].includes(key) && !playheadIds(state.record, state.selection, state.playhead).length) {
@@ -99,6 +101,14 @@ export function createSelectionActions({state, t = en => en, actions = {}, clipb
result.removed && state.selection?.kind === 'gap' ? {selectionAfter: null} : {});
return {ok: !!result.removed, ...(result.removed ? {} : {reason: result.skipped[0]?.code || 'no_gap'}), removed: result.removed, skipped: result.skipped};
}
+ if (key === 'ripple') {
+ const status = deletionStatus(state.record, state.selection);
+ if (!status.ok) return status.reason === 'busy' ? report(new model.EditError(status.reason)) : status;
+ const result = actionsModel.rippleRemoveParts(state.record, ids);
+ state.apply(t('Ripple delete', '波纹删除'), () => result.record, {selectionAfter: null});
+ if (result.skipped.length) actions.notify?.(t('Deleted. The content after it cannot move earlier, so the gap remains.', '已删除。后面的内容无法前移,空隙已保留。'));
+ return {ok: true, closed: result.closed, skipped: result.skipped};
+ }
if (key === 'delete' || key === 'backspace') {
const status = deletionStatus(state.record, state.selection);
if (!status.ok) return status.reason === 'busy' ? report(new model.EditError(status.reason)) : status;
@@ -137,7 +147,7 @@ export function createSelectionActions({state, t = en => en, actions = {}, clipb
const deleting = ['delete', 'backspace'].includes(key) && ['clip', 'gap', 'range'].includes(state.selection?.kind);
const trimming = !event.ctrlKey && !event.metaKey && !event.shiftKey && ['q', 'w'].includes(key);
if (!command && !deleting && !trimming) return false;
- event.preventDefault(); event.stopPropagation(); run(key); return true;
+ event.preventDefault(); event.stopPropagation(); run(deleting && event.shiftKey ? 'ripple' : key); return true;
}};
}
diff --git a/web/editor_transport.js b/web/editor_transport.js
index 85b1c78..537d308 100644
--- a/web/editor_transport.js
+++ b/web/editor_transport.js
@@ -39,6 +39,7 @@ registerShortcuts([
row('redo', 'Ctrl / Cmd + Shift + Z', 'Redo', '重做', 'edit'),
row('split', 'Ctrl / Cmd + B', 'Split', '剪开', 'edit'),
row('delete', 'Delete / Backspace', 'Delete', '删除', 'edit'),
+ row('ripple', 'Shift + Delete / Backspace', 'Delete the selected clip and close the gap', '删除选中的片段并合上空隙', 'edit'),
row('fit', 'Shift + Z', 'Fit all', '看全部', 'timeline', event => !event.ctrlKey && !event.metaKey && !event.altKey && event.shiftKey && event.key.toLowerCase() === 'z'),
]);
export function registerEditorShortcuts(audioRows = [], speedRows = []) {