Files
OpenCut/apps/web/src/lib/commands/batch-command.ts
T

40 lines
852 B
TypeScript
Raw Normal View History

2026-03-31 22:53:16 +02:00
import { Command, type CommandResult } from "./base-command";
2026-02-08 22:21:17 +01:00
export class BatchCommand extends Command {
constructor(private commands: Command[]) {
super();
}
2026-03-31 22:53:16 +02:00
execute(): CommandResult | undefined {
let latestSelectionResult: CommandResult | undefined;
2026-02-08 22:21:17 +01:00
for (const command of this.commands) {
2026-03-31 22:53:16 +02:00
const result = command.execute();
if (result?.select !== undefined) {
latestSelectionResult = result;
}
2026-02-08 22:21:17 +01:00
}
2026-03-31 22:53:16 +02:00
return latestSelectionResult;
2026-02-08 22:21:17 +01:00
}
undo(): void {
for (const command of [...this.commands].reverse()) {
command.undo();
}
}
2026-03-31 22:53:16 +02:00
redo(): CommandResult | undefined {
let latestSelectionResult: CommandResult | undefined;
2026-02-08 22:21:17 +01:00
for (const command of this.commands) {
2026-03-31 22:53:16 +02:00
const result = command.redo();
if (result?.select !== undefined) {
latestSelectionResult = result;
}
2026-02-08 22:21:17 +01:00
}
2026-03-31 22:53:16 +02:00
return latestSelectionResult;
2026-02-08 22:21:17 +01:00
}
}