feat(command_palette): add keyboard shortcut

This commit is contained in:
Elian Doran
2025-07-27 15:34:51 +03:00
parent 3247a9facc
commit 60e19de0d1
5 changed files with 37 additions and 12 deletions

View File

@@ -262,6 +262,7 @@ export type CommandMappings = {
closeThisNoteSplit: CommandData; closeThisNoteSplit: CommandData;
moveThisNoteSplit: CommandData & { isMovingLeft: boolean }; moveThisNoteSplit: CommandData & { isMovingLeft: boolean };
jumpToNote: CommandData; jumpToNote: CommandData;
commandPalette: CommandData;
// Geomap // Geomap
deleteFromMap: { noteId: string }; deleteFromMap: { noteId: string };

View File

@@ -56,6 +56,14 @@ export default class JumpToNoteDialog extends BasicWidget {
} }
async jumpToNoteEvent() { async jumpToNoteEvent() {
await this.openDialog();
}
async commandPaletteEvent() {
await this.openDialog(true);
}
private async openDialog(commandMode = false) {
const dialogPromise = openDialog(this.$widget); const dialogPromise = openDialog(this.$widget);
if (utils.isMobile()) { if (utils.isMobile()) {
dialogPromise.then(($dialog) => { dialogPromise.then(($dialog) => {
@@ -82,12 +90,12 @@ export default class JumpToNoteDialog extends BasicWidget {
} }
// first open dialog, then refresh since refresh is doing focus which should be visible // first open dialog, then refresh since refresh is doing focus which should be visible
this.refresh(); this.refresh(commandMode);
this.lastOpenedTs = Date.now(); this.lastOpenedTs = Date.now();
} }
async refresh() { async refresh(commandMode = false) {
noteAutocompleteService noteAutocompleteService
.initNoteAutocomplete(this.$autoComplete, { .initNoteAutocomplete(this.$autoComplete, {
allowCreatingNotes: true, allowCreatingNotes: true,
@@ -115,6 +123,13 @@ export default class JumpToNoteDialog extends BasicWidget {
this.modal.hide(); this.modal.hide();
}); });
if (commandMode) {
// Start in command mode
this.$autoComplete
.autocomplete("val", ">")
.trigger("focus")
.trigger("select");
} else {
// if you open the Jump To dialog soon after using it previously, it can often mean that you // if you open the Jump To dialog soon after using it previously, it can often mean that you
// actually want to search for the same thing (e.g., you opened the wrong note at first try) // actually want to search for the same thing (e.g., you opened the wrong note at first try)
// so we'll keep the content. // so we'll keep the content.
@@ -130,6 +145,7 @@ export default class JumpToNoteDialog extends BasicWidget {
.trigger("select"); .trigger("select");
} }
} }
}
showInFullText(e: JQuery.TriggeredEvent) { showInFullText(e: JQuery.TriggeredEvent) {
// stop from propagating upwards (dangerous, especially with ctrl+enter executable javascript notes) // stop from propagating upwards (dangerous, especially with ctrl+enter executable javascript notes)

View File

@@ -3,6 +3,7 @@
"back-in-note-history": "Navigate to previous note in history", "back-in-note-history": "Navigate to previous note in history",
"forward-in-note-history": "Navigate to next note in history", "forward-in-note-history": "Navigate to next note in history",
"open-jump-to-note-dialog": "Open \"Jump to note\" dialog", "open-jump-to-note-dialog": "Open \"Jump to note\" dialog",
"open-command-palette": "Open command palette",
"scroll-to-active-note": "Scroll note tree to active note", "scroll-to-active-note": "Scroll note tree to active note",
"quick-search": "Activate quick search bar", "quick-search": "Activate quick search bar",
"search-in-subtree": "Search for notes in the active note's subtree", "search-in-subtree": "Search for notes in the active note's subtree",

View File

@@ -35,6 +35,12 @@ function getDefaultKeyboardActions() {
description: t("keyboard_actions.open-jump-to-note-dialog"), description: t("keyboard_actions.open-jump-to-note-dialog"),
scope: "window" scope: "window"
}, },
{
actionName: "commandPalette",
defaultShortcuts: ["CommandOrControl+Shift+J"],
description: t("keyboard_actions.open-command-palette"),
scope: "window"
},
{ {
actionName: "scrollToActiveNote", actionName: "scrollToActiveNote",
defaultShortcuts: ["CommandOrControl+."], defaultShortcuts: ["CommandOrControl+."],

View File

@@ -2,6 +2,7 @@ const enum KeyboardActionNamesEnum {
backInNoteHistory, backInNoteHistory,
forwardInNoteHistory, forwardInNoteHistory,
jumpToNote, jumpToNote,
commandPalette,
scrollToActiveNote, scrollToActiveNote,
quickSearch, quickSearch,
searchInSubtree, searchInSubtree,