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

This commit is contained in:
Elian Doran 2025-07-30 19:50:07 +03:00
parent f6e275709f
commit 7fc739487f
No known key found for this signature in database
4 changed files with 26 additions and 26 deletions

View File

@ -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];

View File

@ -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> = {};
const keyboardActionRepo: Record<string, ActionKeyboardShortcut> = {};
// TODO: Deduplicate with server.
export interface Action {
actionName: CommandNames;
effectiveShortcuts: string[];
scope: string;
friendlyName: string;
description?: string;
iconClass?: string;
isElectronOnly?: boolean;
}
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;

View File

@ -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",

View File

@ -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;