blob: c4ee7e0b23878df8cc869eb4055619474c9c6c8d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
import { Command, type CommandResult } from "./base-command";
export class BatchCommand extends Command {
constructor(private commands: Command[]) {
super();
}
execute(): CommandResult | undefined {
let latestSelectionResult: CommandResult | undefined;
for (const command of this.commands) {
const result = command.execute();
if (result?.selection !== undefined) {
latestSelectionResult = result;
}
}
return latestSelectionResult;
}
undo(): void {
for (const command of [...this.commands].reverse()) {
command.undo();
}
}
redo(): CommandResult | undefined {
let latestSelectionResult: CommandResult | undefined;
for (const command of this.commands) {
const result = command.redo();
if (result?.selection !== undefined) {
latestSelectionResult = result;
}
}
return latestSelectionResult;
}
}
|