Skip to content

OpenReel Video - Professional browser-based video editor. Open source CapCut alternative. 100% browser-based, no installation, no cloud uploads, no watermarks.

TypeScript

fix(editor): batch undo for auto cut silence operations

Augustus Otu379cae208bc8
diff --git a/apps/web/src/bridges/silence-cut-bridge.ts b/apps/web/src/bridges/silence-cut-bridge.ts
index cedbe7db..90306f8e 100644
--- a/apps/web/src/bridges/silence-cut-bridge.ts
+++ b/apps/web/src/bridges/silence-cut-bridge.ts
@@ -144,6 +144,9 @@ export class SilenceCutBridge {
onProgress?.(0, "Preparing cuts...");
+ const actionHistory = store.actionHistory;
+ actionHistory.beginGroup("Cut silence");
+
try {
for (let i = 0; i < sortedRegions.length; i++) {
const region = sortedRegions[i];
@@ -202,6 +205,8 @@ export class SilenceCutBridge {
const message =
error instanceof Error ? error.message : "Unknown error occurred";
return { success: false, error: message };
+ } finally {
+ actionHistory.endGroup();
}
}
diff --git a/packages/core/src/actions/action-executor.ts b/packages/core/src/actions/action-executor.ts
index 8131aa25..bf122a95 100644
--- a/packages/core/src/actions/action-executor.ts
+++ b/packages/core/src/actions/action-executor.ts
@@ -113,8 +113,8 @@ export class ActionExecutor {
};
}
- const inverseAction = this.history.undo();
- if (!inverseAction) {
+ const inverseActions = this.history.undoGroup();
+ if (inverseActions.length === 0) {
return {
success: false,
error: {
@@ -124,12 +124,12 @@ export class ActionExecutor {
};
}
- // Resolve any special markers in the inverse action
- const resolvedAction = this.resolveSpecialMarkers(inverseAction);
-
try {
- await this.applyAction(resolvedAction as TimelineAction, project);
- return { success: true, actionId: inverseAction.id };
+ for (const inverseAction of inverseActions) {
+ const resolvedAction = this.resolveSpecialMarkers(inverseAction);
+ await this.applyAction(resolvedAction as TimelineAction, project);
+ }
+ return { success: true, actionId: inverseActions[0].id };
} catch (error) {
return {
success: false,
@@ -152,8 +152,8 @@ export class ActionExecutor {
};
}
- const action = this.history.redo();
- if (!action) {
+ const actions = this.history.redoGroup();
+ if (actions.length === 0) {
return {
success: false,
error: {
@@ -164,8 +164,10 @@ export class ActionExecutor {
}
try {
- await this.applyAction(action as TimelineAction, project);
- return { success: true, actionId: action.id };
+ for (const action of actions) {
+ await this.applyAction(action as TimelineAction, project);
+ }
+ return { success: true, actionId: actions[0].id };
} catch (error) {
return {
success: false,