From fa9b142cb7a86e6737060c1d949da8443e13ae3f Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 27 Jul 2025 21:03:31 +0300 Subject: [PATCH] fix(command_palette): triggering note tree actions --- apps/client/src/services/command_registry.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/apps/client/src/services/command_registry.ts b/apps/client/src/services/command_registry.ts index 7e32b79d4..5bb4bbde6 100644 --- a/apps/client/src/services/command_registry.ts +++ b/apps/client/src/services/command_registry.ts @@ -1,4 +1,5 @@ import appContext, { type CommandNames } from "../components/app_context.js"; +import type NoteTreeWidget from "../widgets/note_tree.js"; import keyboardActions from "./keyboard_actions.js"; export interface CommandDefinition { @@ -166,6 +167,9 @@ class CommandRegistry { continue; } + // Note-tree scoped actions need special handling + const needsFocusEmulation = action.scope === "note-tree"; + // Get the primary shortcut (first one in the list) const primaryShortcut = action.effectiveShortcuts?.[0]; @@ -177,7 +181,8 @@ class CommandRegistry { icon: action.iconClass || this.getIconForAction(action.actionName), shortcut: primaryShortcut ? this.formatShortcut(primaryShortcut) : undefined, commandName: action.actionName as CommandNames, - source: "keyboard-action" + source: "keyboard-action", + handler: needsFocusEmulation ? () => this.executeWithNoteTreeFocus(action.actionName) : undefined }; this.register(commandDef); @@ -328,6 +333,16 @@ class CommandRegistry { console.error(`Command ${commandId} has no handler or commandName`); } } + + private executeWithNoteTreeFocus(actionName: CommandNames) { + const tree = document.querySelector(".tree-wrapper") as HTMLElement; + if (!tree) { + return; + } + + const treeComponent = appContext.getComponentByEl(tree) as NoteTreeWidget; + treeComponent.triggerCommand(actionName, { ntxId: appContext.tabManager.activeNtxId }); + } } const commandRegistry = new CommandRegistry();