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();
|
2026-04-18 16:01:35 +02:00
|
|
|
if (result?.selection !== undefined) {
|
2026-03-31 22:53:16 +02:00
|
|
|
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();
|
2026-04-18 16:01:35 +02:00
|
|
|
if (result?.selection !== undefined) {
|
2026-03-31 22:53:16 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|