mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 02:45:54 +01:00
fix(command_palette): triggering note tree actions
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import appContext, { type CommandNames } from "../components/app_context.js";
|
import appContext, { type CommandNames } from "../components/app_context.js";
|
||||||
|
import type NoteTreeWidget from "../widgets/note_tree.js";
|
||||||
import keyboardActions from "./keyboard_actions.js";
|
import keyboardActions from "./keyboard_actions.js";
|
||||||
|
|
||||||
export interface CommandDefinition {
|
export interface CommandDefinition {
|
||||||
@@ -166,6 +167,9 @@ class CommandRegistry {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note-tree scoped actions need special handling
|
||||||
|
const needsFocusEmulation = action.scope === "note-tree";
|
||||||
|
|
||||||
// Get the primary shortcut (first one in the list)
|
// Get the primary shortcut (first one in the list)
|
||||||
const primaryShortcut = action.effectiveShortcuts?.[0];
|
const primaryShortcut = action.effectiveShortcuts?.[0];
|
||||||
|
|
||||||
@@ -177,7 +181,8 @@ class CommandRegistry {
|
|||||||
icon: action.iconClass || this.getIconForAction(action.actionName),
|
icon: action.iconClass || this.getIconForAction(action.actionName),
|
||||||
shortcut: primaryShortcut ? this.formatShortcut(primaryShortcut) : undefined,
|
shortcut: primaryShortcut ? this.formatShortcut(primaryShortcut) : undefined,
|
||||||
commandName: action.actionName as CommandNames,
|
commandName: action.actionName as CommandNames,
|
||||||
source: "keyboard-action"
|
source: "keyboard-action",
|
||||||
|
handler: needsFocusEmulation ? () => this.executeWithNoteTreeFocus(action.actionName) : undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
this.register(commandDef);
|
this.register(commandDef);
|
||||||
@@ -328,6 +333,16 @@ class CommandRegistry {
|
|||||||
console.error(`Command ${commandId} has no handler or commandName`);
|
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();
|
const commandRegistry = new CommandRegistry();
|
||||||
|
|||||||
Reference in New Issue
Block a user