Skip to content

Build your personal knowledge base with Trilium Notes

chore(command_palette): hide jump to note / command palette

Elian Doran7fc739487fdd
diff --git a/apps/client/src/services/command_registry.ts b/apps/client/src/services/command_registry.ts
index 8f045d57d0..a8721e43f3 100644
--- a/apps/client/src/services/command_registry.ts
+++ b/apps/client/src/services/command_registry.ts
@@ -1,7 +1,8 @@
+import { ActionKeyboardShortcut } from "@triliumnext/commons";
import appContext, { type CommandNames } from "../components/app_context.js";
import type NoteTreeWidget from "../widgets/note_tree.js";
import { t, translationsInitializedPromise } from "./i18n.js";
-import keyboardActions, { Action } from "./keyboard_actions.js";
+import keyboardActions from "./keyboard_actions.js";
import utils from "./utils.js";
export interface CommandDefinition {
@@ -15,7 +16,7 @@ export interface CommandDefinition {
aliases?: string[];
source?: "manual" | "keyboard-action";
/** Reference to the original keyboard action for scope checking. */
- keyboardAction?: Action;
+ keyboardAction?: ActionKeyboardShortcut;
}
class CommandRegistry {
@@ -105,7 +106,7 @@ class CommandRegistry {
}
}
- private registerKeyboardActions(actions: Action[]) {
+ private registerKeyboardActions(actions: ActionKeyboardShortcut[]) {
for (const action of actions) {
// Skip actions that we've already manually registered
if (this.commands.has(action.actionName)) {
@@ -122,6 +123,11 @@ class CommandRegistry {
continue;
}
+ // Skip actions that should not appear in the command palette
+ if (action.ignoreFromCommandPalette) {
+ continue;
+ }
+
// Get the primary shortcut (first one in the list)
const primaryShortcut = action.effectiveShortcuts?.[0];
diff --git a/apps/client/src/services/keyboard_actions.ts b/apps/client/src/services/keyboard_actions.ts
index 820de185ca..c72ba29bb7 100644
--- a/apps/client/src/services/keyboard_actions.ts
+++ b/apps/client/src/services/keyboard_actions.ts
@@ -2,25 +2,15 @@ import server from "./server.js";
import appContext, { type CommandNames } from "../components/app_context.js";
import shortcutService from "./shortcuts.js";
import type Component from "../components/component.js";
+import type { ActionKeyboardShortcut } from "@triliumnext/commons";
-const keyboardActionRepo: Record<string, Action> = {};
-
-// TODO: Deduplicate with server.
-export interface Action {
- actionName: CommandNames;
- effectiveShortcuts: string[];
- scope: string;
- friendlyName: string;
- description?: string;
- iconClass?: string;
- isElectronOnly?: boolean;
-}
+const keyboardActionRepo: Record<string, ActionKeyboardShortcut> = {};
-const keyboardActionsLoaded = server.get<Action[]>("keyboard-actions").then((actions) => {
+const keyboardActionsLoaded = server.get<ActionKeyboardShortcut[]>("keyboard-actions").then((actions) => {
actions = actions.filter((a) => !!a.actionName); // filter out separators
for (const action of actions) {
- action.effectiveShortcuts = action.effectiveShortcuts.filter((shortcut) => !shortcut.startsWith("global:"));
+ action.effectiveShortcuts = (action.effectiveShortcuts ?? []).filter((shortcut) => !shortcut.startsWith("global:"));
keyboardActionRepo[action.actionName] = action;
}
@@ -42,7 +32,7 @@ async function setupActionsForElement(scope: string, $el: JQuery<HTMLElement>, c
const actions = await getActionsForScope(scope);
for (const action of actions) {
- for (const shortcut of action.effectiveShortcuts) {
+ for (const shortcut of action.effectiveShortcuts ?? []) {
shortcutService.bindElShortcut($el, shortcut, () => component.triggerCommand(action.actionName, { ntxId: appContext.tabManager.activeNtxId }));
}
}
@@ -50,7 +40,7 @@ async function setupActionsForElement(scope: string, $el: JQuery<HTMLElement>, c
getActionsForScope("window").then((actions) => {
for (const action of actions) {
- for (const shortcut of action.effectiveShortcuts) {
+ for (const shortcut of action.effectiveShortcuts ?? []) {
shortcutService.bindGlobalShortcut(shortcut, () => appContext.triggerCommand(action.actionName, { ntxId: appContext.tabManager.activeNtxId }));
}
}
@@ -84,7 +74,7 @@ function updateDisplayedShortcuts($container: JQuery<HTMLElement>) {
const action = await getAction(actionName, true);
if (action) {
- const keyboardActions = action.effectiveShortcuts.join(", ");
+ const keyboardActions = (action.effectiveShortcuts ?? []).join(", ");
if (keyboardActions || $(el).text() !== "not set") {
$(el).text(keyboardActions);
@@ -103,7 +93,7 @@ function updateDisplayedShortcuts($container: JQuery<HTMLElement>) {
if (action) {
const title = $(el).attr("title");
- const shortcuts = action.effectiveShortcuts.join(", ");
+ const shortcuts = (action.effectiveShortcuts ?? []).join(", ");
if (title?.includes(shortcuts)) {
return;
diff --git a/apps/server/src/services/keyboard_actions.ts b/apps/server/src/services/keyboard_actions.ts
index bf65121be9..5e5807fd0c 100644
--- a/apps/server/src/services/keyboard_actions.ts
+++ b/apps/server/src/services/keyboard_actions.ts
@@ -36,18 +36,18 @@ function getDefaultKeyboardActions() {
{
actionName: "jumpToNote",
friendlyName: t("keyboard_action_names.jump-to-note"),
- iconClass: "bx bx-send",
defaultShortcuts: ["CommandOrControl+J"],
description: t("keyboard_actions.open-jump-to-note-dialog"),
- scope: "window"
+ scope: "window",
+ ignoreFromCommandPalette: true
},
{
actionName: "commandPalette",
friendlyName: t("keyboard_action_names.command-palette"),
- iconClass: "bx bx-terminal",
defaultShortcuts: ["CommandOrControl+Shift+J"],
description: t("keyboard_actions.open-command-palette"),
- scope: "window"
+ scope: "window",
+ ignoreFromCommandPalette: true
},
{
actionName: "scrollToActiveNote",
diff --git a/packages/commons/src/lib/keyboard_actions_interface.ts b/packages/commons/src/lib/keyboard_actions_interface.ts
index 9b73e48b25..c3de7e0dbb 100644
--- a/packages/commons/src/lib/keyboard_actions_interface.ts
+++ b/packages/commons/src/lib/keyboard_actions_interface.ts
@@ -112,7 +112,7 @@ export interface ActionKeyboardShortcut {
* An icon describing the action.
* This is currently only used in the command palette.
*/
- iconClass: string;
+ iconClass?: string;
/**
* Scope here means on which element the keyboard shortcuts are attached - this means that for the shortcut to work,
* the focus has to be inside the element.
@@ -127,6 +127,10 @@ export interface ActionKeyboardShortcut {
* This is used to hide actions that are not available in the web version.
*/
isElectronOnly?: boolean;
+ /**
+ * If set to true, the action will not be shown in the command palette.
+ */
+ ignoreFromCommandPalette?: boolean;
}
export type KeyboardShortcut = ActionKeyboardShortcut | KeyboardShortcutSeparator;