continution from undo selection refactor

This commit is contained in:
Maze Winther 2026-01-27 17:52:29 +01:00
parent 9fc9a8ccc0
commit 5d08b16867
3 changed files with 22 additions and 11 deletions

View File

@ -220,10 +220,9 @@ export function useEditorActions() {
useActionHandler(
"duplicate-selected",
() => {
const duplicatedElements = editor.timeline.duplicateElements({
elements: selectedElements,
});
setElementSelection({ elements: duplicatedElements });
editor.timeline.duplicateElements({
elements: selectedElements,
});
},
undefined,
);
@ -277,14 +276,12 @@ export function useEditorActions() {
useActionHandler(
"paste-copied",
() => {
if (!clipboard?.items.length) return;
if (!clipboard?.items.length) return;
const pastedElements =
editor.timeline.pasteAtTime({
time: editor.playback.getCurrentTime(),
clipboardItems: clipboard.items,
}) ?? [];
setElementSelection({ elements: pastedElements });
editor.timeline.pasteAtTime({
time: editor.playback.getCurrentTime(),
clipboardItems: clipboard.items,
});
},
undefined,
);

View File

@ -15,6 +15,7 @@ import {
export class PasteCommand extends Command {
private savedState: TimelineTrack[] | null = null;
private pastedElements: { trackId: string; elementId: string }[] = [];
private previousSelection: { trackId: string; elementId: string }[] = [];
constructor(
private time: number,
@ -28,6 +29,7 @@ export class PasteCommand extends Command {
const editor = EditorCore.getInstance();
this.savedState = editor.timeline.getTracks();
this.previousSelection = editor.selection.getSelectedElements();
this.pastedElements = [];
const minStart = Math.min(
@ -95,12 +97,17 @@ export class PasteCommand extends Command {
}
editor.timeline.updateTracks(updatedTracks);
if (this.pastedElements.length > 0) {
editor.selection.setSelectedElements({ elements: this.pastedElements });
}
}
undo(): void {
if (this.savedState) {
const editor = EditorCore.getInstance();
editor.timeline.updateTracks(this.savedState);
editor.selection.setSelectedElements({ elements: this.previousSelection });
}
}

View File

@ -14,6 +14,7 @@ interface DuplicateElementsParams {
export class DuplicateElementsCommand extends Command {
private duplicatedElements: { trackId: string; elementId: string }[] = [];
private savedState: TimelineTrack[] | null = null;
private previousSelection: { trackId: string; elementId: string }[] = [];
private elements: DuplicateElementsParams["elements"];
constructor({ elements }: DuplicateElementsParams) {
@ -24,6 +25,7 @@ export class DuplicateElementsCommand extends Command {
execute(): void {
const editor = EditorCore.getInstance();
this.savedState = editor.timeline.getTracks();
this.previousSelection = editor.selection.getSelectedElements();
this.duplicatedElements = [];
const updatedTracks = [...this.savedState];
@ -80,12 +82,17 @@ export class DuplicateElementsCommand extends Command {
}
editor.timeline.updateTracks(updatedTracks);
if (this.duplicatedElements.length > 0) {
editor.selection.setSelectedElements({ elements: this.duplicatedElements });
}
}
undo(): void {
if (this.savedState) {
const editor = EditorCore.getInstance();
editor.timeline.updateTracks(this.savedState);
editor.selection.setSelectedElements({ elements: this.previousSelection });
}
}