From f8fb238b228881ef970739b7d884912058b41347 Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Tue, 31 Mar 2026 22:53:16 +0200 Subject: feat: centralize selection management --- apps/web/src/lib/commands/batch-command.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'apps/web/src/lib/commands/batch-command.ts') diff --git a/apps/web/src/lib/commands/batch-command.ts b/apps/web/src/lib/commands/batch-command.ts index 05b51d38..ea23411c 100644 --- a/apps/web/src/lib/commands/batch-command.ts +++ b/apps/web/src/lib/commands/batch-command.ts @@ -1,14 +1,21 @@ -import { Command } from "./base-command"; +import { Command, type CommandResult } from "./base-command"; export class BatchCommand extends Command { constructor(private commands: Command[]) { super(); } - execute(): void { + execute(): CommandResult | undefined { + let latestSelectionResult: CommandResult | undefined; + for (const command of this.commands) { - command.execute(); + const result = command.execute(); + if (result?.select !== undefined) { + latestSelectionResult = result; + } } + + return latestSelectionResult; } undo(): void { @@ -17,9 +24,16 @@ export class BatchCommand extends Command { } } - redo(): void { + redo(): CommandResult | undefined { + let latestSelectionResult: CommandResult | undefined; + for (const command of this.commands) { - command.execute(); + const result = command.redo(); + if (result?.select !== undefined) { + latestSelectionResult = result; + } } + + return latestSelectionResult; } } -- cgit v1.3.1