Skip to content

Commit 8bdc894

Browse files
committed
fix: migrate commands to CommandResult selection contract
1 parent 0387bd4 commit 8bdc894

File tree

6 files changed

+51
-19
lines changed

6 files changed

+51
-19
lines changed

apps/web/src/lib/commands/base-command.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
import type { EditorSelectionPatch } from "@/lib/selection/editor-selection";
2+
import type { ElementRef } from "@/lib/timeline/types";
23

34
export interface CommandResult {
45
selection?: EditorSelectionPatch;
56
}
67

8+
export function createElementSelectionResult(
9+
selectedElements: ElementRef[],
10+
): CommandResult {
11+
return {
12+
selection: {
13+
selectedElements,
14+
selectedKeyframes: [],
15+
keyframeSelectionAnchor: null,
16+
selectedMaskPoints: null,
17+
},
18+
};
19+
}
20+
721
export abstract class Command {
822
abstract execute(): CommandResult | undefined;
923

apps/web/src/lib/commands/batch-command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class BatchCommand extends Command {
1010

1111
for (const command of this.commands) {
1212
const result = command.execute();
13-
if (result?.select !== undefined) {
13+
if (result?.selection !== undefined) {
1414
latestSelectionResult = result;
1515
}
1616
}
@@ -29,7 +29,7 @@ export class BatchCommand extends Command {
2929

3030
for (const command of this.commands) {
3131
const result = command.redo();
32-
if (result?.select !== undefined) {
32+
if (result?.selection !== undefined) {
3333
latestSelectionResult = result;
3434
}
3535
}

apps/web/src/lib/commands/timeline/clipboard/paste.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
import { Command, type CommandResult } from "@/lib/commands/base-command";
1+
import {
2+
Command,
3+
createElementSelectionResult,
4+
type CommandResult,
5+
} from "@/lib/commands/base-command";
26
import { EditorCore } from "@/core";
37
import type { SceneTracks, TimelineElement } from "@/lib/timeline";
48
import type { ElementClipboardItem } from "@/lib/clipboard";
59
import { generateUUID } from "@/utils/id";
6-
import { applyPlacement, resolveTrackPlacement, enforceMainTrackStart } from "@/lib/timeline/placement";
10+
import {
11+
applyPlacement,
12+
resolveTrackPlacement,
13+
enforceMainTrackStart,
14+
} from "@/lib/timeline/placement";
715
import { cloneAnimations } from "@/lib/animation";
816

917
export class PasteCommand extends Command {
@@ -122,7 +130,7 @@ export class PasteCommand extends Command {
122130
editor.timeline.updateTracks(updatedTracks);
123131

124132
if (this.pastedElements.length > 0) {
125-
return { select: this.pastedElements };
133+
return createElementSelectionResult(this.pastedElements);
126134
}
127135
return undefined;
128136
}
@@ -183,4 +191,3 @@ function buildPastedElements({
183191

184192
return elementsToAdd;
185193
}
186-

apps/web/src/lib/commands/timeline/element/duplicate-elements.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
import { Command, type CommandResult } from "@/lib/commands/base-command";
1+
import {
2+
Command,
3+
createElementSelectionResult,
4+
type CommandResult,
5+
} from "@/lib/commands/base-command";
26
import type { SceneTracks, TimelineElement } from "@/lib/timeline";
37
import { generateUUID } from "@/utils/id";
48
import { EditorCore } from "@/core";
5-
import { applyPlacement, resolveTrackPlacement } from "@/lib/timeline/placement";
9+
import {
10+
applyPlacement,
11+
resolveTrackPlacement,
12+
} from "@/lib/timeline/placement";
613
import { cloneAnimations } from "@/lib/animation";
714

815
interface DuplicateElementsParams {
@@ -91,9 +98,7 @@ export class DuplicateElementsCommand extends Command {
9198
editor.timeline.updateTracks(updatedTracks);
9299

93100
if (this.duplicatedElements.length > 0) {
94-
return {
95-
select: this.duplicatedElements,
96-
};
101+
return createElementSelectionResult(this.duplicatedElements);
97102
}
98103
return undefined;
99104
}

apps/web/src/lib/commands/timeline/element/move-elements.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { Command, type CommandResult } from "@/lib/commands/base-command";
1+
import {
2+
Command,
3+
createElementSelectionResult,
4+
type CommandResult,
5+
} from "@/lib/commands/base-command";
26
import { EditorCore } from "@/core";
37
import type {
48
SceneTracks,
@@ -114,12 +118,12 @@ export class MoveElementCommand extends Command {
114118
});
115119

116120
editor.timeline.updateTracks(updatedTracks);
117-
return {
118-
select: this.moves.map(({ elementId, targetTrackId }) => ({
121+
return createElementSelectionResult(
122+
this.moves.map(({ elementId, targetTrackId }) => ({
119123
trackId: targetTrackId,
120124
elementId,
121125
})),
122-
};
126+
);
123127
}
124128

125129
undo(): void {

apps/web/src/lib/commands/timeline/element/split-elements.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { Command, type CommandResult } from "@/lib/commands/base-command";
1+
import {
2+
Command,
3+
createElementSelectionResult,
4+
type CommandResult,
5+
} from "@/lib/commands/base-command";
26
import type { SceneTracks, TimelineElement } from "@/lib/timeline";
37
import { generateUUID } from "@/utils/id";
48
import { EditorCore } from "@/core";
@@ -164,9 +168,7 @@ export class SplitElementsCommand extends Command {
164168
editor.timeline.updateTracks(updatedTracks);
165169

166170
if (this.rightSideElements.length > 0) {
167-
return {
168-
select: this.rightSideElements,
169-
};
171+
return createElementSelectionResult(this.rightSideElements);
170172
}
171173
return undefined;
172174
}

0 commit comments

Comments
 (0)