From f3fdc0c9a2e44e8074604c500855711abc7652ea Mon Sep 17 00:00:00 2001 From: Matt Hillsdon Date: Tue, 15 Apr 2025 13:12:38 +0100 Subject: [PATCH 1/2] feat: auto confirm a move on subsequent action --- src/actions/move.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/actions/move.ts b/src/actions/move.ts index 415fe40c..de63921b 100644 --- a/src/actions/move.ts +++ b/src/actions/move.ts @@ -25,6 +25,13 @@ const createSerializedKey = ShortcutRegistry.registry.createSerializedKey.bind( * Actions for moving blocks with keyboard shortcuts. */ export class MoveActions { + /** + * Stored to enable us to restore monkey patch. + */ + private oldShortcutRegistryOnKeyDown: + | typeof ShortcutRegistry.registry.onKeyDown + | null = null; + constructor(private mover: Mover) {} private shortcutNames: string[] = []; @@ -189,6 +196,32 @@ export class MoveActions { install() { this.registerShortcuts(); this.registerMenuItems(); + + // Monkey patch shortcut registry to finish any in-progress move for all + // non-move-related actions. + this.oldShortcutRegistryOnKeyDown = ShortcutRegistry.registry.onKeyDown; + ShortcutRegistry.registry.onKeyDown = (workspace, e) => { + if (!this.oldShortcutRegistryOnKeyDown) return false; + // @ts-expect-error private method + const key = ShortcutRegistry.registry.serializeKeyEvent(e); + const moveShortcutNames = + ShortcutRegistry.registry.getShortcutNamesByKeyCode(key); + if ( + !this.shortcuts.some((shortcut) => + moveShortcutNames?.includes(shortcut.name), + ) + ) { + if (this.mover.isMoving(workspace)) { + this.mover.finishMove(workspace); + } + } + + return this.oldShortcutRegistryOnKeyDown.call( + ShortcutRegistry.registry, + workspace, + e, + ); + }; } /** @@ -201,6 +234,10 @@ export class MoveActions { for (const menuItem of this.menuItemNames) { ContextMenuRegistry.registry.unregister(menuItem); } + + if (this.oldShortcutRegistryOnKeyDown) { + ShortcutRegistry.registry.onKeyDown = this.oldShortcutRegistryOnKeyDown; + } } /** From b0024e791f22664c329f61b8083d07bd8a64defc Mon Sep 17 00:00:00 2001 From: Matt Hillsdon Date: Thu, 29 May 2025 14:16:40 +0100 Subject: [PATCH 2/2] feat: extend monkey patch to cover ephemeral focus --- src/actions/move.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/actions/move.ts b/src/actions/move.ts index de63921b..cc13ce23 100644 --- a/src/actions/move.ts +++ b/src/actions/move.ts @@ -7,6 +7,7 @@ import { BlockSvg, ContextMenuRegistry, + FocusManager, Msg, ShortcutRegistry, utils, @@ -197,18 +198,19 @@ export class MoveActions { this.registerShortcuts(); this.registerMenuItems(); - // Monkey patch shortcut registry to finish any in-progress move for all - // non-move-related actions. + // Monkey patch shortcut registry to: finish any in-progress move for all + // non-move-related actions and bail on actions other than "escape" during + // ephemeral focus. this.oldShortcutRegistryOnKeyDown = ShortcutRegistry.registry.onKeyDown; ShortcutRegistry.registry.onKeyDown = (workspace, e) => { if (!this.oldShortcutRegistryOnKeyDown) return false; // @ts-expect-error private method const key = ShortcutRegistry.registry.serializeKeyEvent(e); - const moveShortcutNames = + const shortcutNamesForKey = ShortcutRegistry.registry.getShortcutNamesByKeyCode(key); if ( - !this.shortcuts.some((shortcut) => - moveShortcutNames?.includes(shortcut.name), + !this.shortcutNames.some((moveShortcutName) => + shortcutNamesForKey?.includes(moveShortcutName), ) ) { if (this.mover.isMoving(workspace)) { @@ -216,6 +218,15 @@ export class MoveActions { } } + // @ts-expect-error private method + const {currentlyHoldsEphemeralFocus} = FocusManager.getFocusManager(); + if ( + currentlyHoldsEphemeralFocus && + !shortcutNamesForKey?.includes('escape') + ) { + return false; + } + return this.oldShortcutRegistryOnKeyDown.call( ShortcutRegistry.registry, workspace,