Notes/src/services/keyboard_actions.ts

648 lines
19 KiB
TypeScript
Raw Normal View History

2019-11-19 20:53:04 +01:00
"use strict";
import optionService from "./options.js";
import log from "./log.js";
import utils from "./utils.js";
import { KeyboardShortcut } from './keyboard_actions_interface.js';
import { t } from "i18next";
2019-11-19 20:53:04 +01:00
2019-11-24 09:50:19 +01:00
const isMac = process.platform === "darwin";
const isElectron = utils.isElectron();
2019-11-18 23:01:31 +01:00
/**
* 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.
*
* So e.g. shortcuts with "note-tree" scope work only when the focus is in note tree.
* This allows to have the same shortcut have different actions attached based on the context
* e.g. CTRL-C in note tree does something a bit different from CTRL-C in the text editor.
*/
if (!t("keyboard_actions.note-navigation")) {
throw new Error("Keyboard actions loaded before translations.");
}
2024-02-17 19:29:15 +02:00
const DEFAULT_KEYBOARD_ACTIONS: KeyboardShortcut[] = [
2019-11-20 23:10:41 +01:00
{
2024-09-08 15:33:06 +03:00
separator: t("keyboard_actions.note-navigation")
2019-11-20 23:10:41 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "backInNoteHistory",
2019-11-24 09:50:19 +01:00
// Mac has a different history navigation shortcuts - https://github.com/zadam/trilium/issues/376
defaultShortcuts: isMac ? ["CommandOrControl+Left"] : ["Alt+Left"],
scope: "window"
2019-11-20 23:10:41 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "forwardInNoteHistory",
2019-11-24 09:50:19 +01:00
// Mac has a different history navigation shortcuts - https://github.com/zadam/trilium/issues/376
defaultShortcuts: isMac ? ["CommandOrControl+Right"] : ["Alt+Right"],
scope: "window"
2019-11-20 23:10:41 +01:00
},
2019-11-18 23:01:31 +01:00
{
2020-02-19 20:54:14 +01:00
actionName: "jumpToNote",
defaultShortcuts: ["CommandOrControl+J"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.open-jump-to-note-dialog"),
scope: "window"
2019-11-18 23:01:31 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "scrollToActiveNote",
defaultShortcuts: ["CommandOrControl+."],
2020-06-03 11:06:45 +02:00
scope: "window"
2019-11-20 23:10:41 +01:00
},
{
2021-02-01 23:51:04 +01:00
actionName: "quickSearch",
defaultShortcuts: ["CommandOrControl+S"],
scope: "window"
2019-11-20 23:10:41 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "searchInSubtree",
defaultShortcuts: ["CommandOrControl+Shift+S"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.search-in-subtree"),
scope: "note-tree"
2019-11-20 23:10:41 +01:00
},
{
actionName: "expandSubtree",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.expand-subtree"),
scope: "note-tree"
},
2019-11-20 23:10:41 +01:00
{
2020-02-19 20:54:14 +01:00
actionName: "collapseTree",
defaultShortcuts: ["Alt+C"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.collapse-tree"),
2020-06-03 11:06:45 +02:00
scope: "window"
2019-11-20 23:10:41 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "collapseSubtree",
defaultShortcuts: ["Alt+-"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.collapse-subtree"),
scope: "note-tree"
2019-11-20 23:10:41 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "sortChildNotes",
defaultShortcuts: ["Alt+S"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.sort-child-notes"),
scope: "note-tree"
2019-11-20 23:10:41 +01:00
},
{
2024-09-08 15:33:06 +03:00
separator: t("keyboard_actions.creating-and-moving-notes")
},
2019-11-18 23:01:31 +01:00
{
2020-02-19 20:54:14 +01:00
actionName: "createNoteAfter",
defaultShortcuts: ["CommandOrControl+O"],
scope: "window"
2019-11-18 23:01:31 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "createNoteInto",
defaultShortcuts: ["CommandOrControl+P"],
scope: "window"
},
{
2020-11-27 22:21:13 +01:00
actionName: "createNoteIntoInbox",
defaultShortcuts: ["global:CommandOrControl+Alt+P"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.create-note-into-inbox"),
scope: "window"
2019-11-18 23:01:31 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "deleteNotes",
2019-11-21 22:24:07 +01:00
defaultShortcuts: ["Delete"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.delete-note"),
scope: "note-tree"
2019-11-21 22:24:07 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "moveNoteUp",
defaultShortcuts: isMac ? ["Alt+Up"] : ["CommandOrControl+Up"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.move-note-up"),
scope: "note-tree"
2019-11-21 22:24:07 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "moveNoteDown",
defaultShortcuts: isMac ? ["Alt+Down"] : ["CommandOrControl+Down"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.move-note-down"),
scope: "note-tree"
2019-11-21 22:24:07 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "moveNoteUpInHierarchy",
defaultShortcuts: isMac ? ["Alt+Left"] : ["CommandOrControl+Left"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.move-note-up-in-hierarchy"),
scope: "note-tree"
2019-11-21 22:24:07 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "moveNoteDownInHierarchy",
defaultShortcuts: isMac ? ["Alt+Right"] : ["CommandOrControl+Right"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.move-note-down-in-hierarchy"),
scope: "note-tree"
2019-11-21 22:24:07 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "editNoteTitle",
defaultShortcuts: ["Enter"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.edit-note-title"),
scope: "note-tree"
2019-11-21 22:24:07 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "editBranchPrefix",
defaultShortcuts: ["F2"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.edit-branch-prefix"),
scope: "note-tree"
},
{
2020-02-19 20:54:14 +01:00
actionName: "cloneNotesTo",
defaultShortcuts: ["CommandOrControl+Shift+C"],
scope: "window"
2019-11-21 22:24:07 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "moveNotesTo",
defaultShortcuts: ["CommandOrControl+Shift+X"],
scope: "window"
},
{
2024-09-08 15:33:06 +03:00
separator: t("keyboard_actions.note-clipboard")
},
2019-11-21 22:24:07 +01:00
{
2020-02-19 20:54:14 +01:00
actionName: "copyNotesToClipboard",
defaultShortcuts: ["CommandOrControl+C"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.copy-notes-to-clipboard"),
scope: "note-tree"
2019-11-18 23:01:31 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "pasteNotesFromClipboard",
defaultShortcuts: ["CommandOrControl+V"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.paste-notes-from-clipboard"),
scope: "note-tree"
2019-11-18 23:01:31 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "cutNotesToClipboard",
defaultShortcuts: ["CommandOrControl+X"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.cut-notes-to-clipboard"),
scope: "note-tree"
2019-11-18 23:01:31 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "selectAllNotesInParent",
defaultShortcuts: ["CommandOrControl+A"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.select-all-notes-in-parent"),
scope: "note-tree"
2019-11-20 23:10:41 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "addNoteAboveToSelection",
defaultShortcuts: ["Shift+Up"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.add-note-above-to-the-selection"),
scope: "note-tree"
2019-11-21 22:24:07 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "addNoteBelowToSelection",
defaultShortcuts: ["Shift+Down"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.add-note-below-to-selection"),
scope: "note-tree"
2019-11-21 22:24:07 +01:00
},
{
actionName: "duplicateSubtree",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.duplicate-subtree"),
scope: "note-tree"
},
2019-11-21 22:24:07 +01:00
{
2024-09-08 15:33:06 +03:00
separator: t("keyboard_actions.tabs-and-windows")
2019-11-21 22:24:07 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "openNewTab",
2019-11-24 22:15:33 +01:00
defaultShortcuts: isElectron ? ["CommandOrControl+T"] : [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.open-new-tab"),
scope: "window"
2019-11-18 23:01:31 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "closeActiveTab",
2019-11-24 22:15:33 +01:00
defaultShortcuts: isElectron ? ["CommandOrControl+W"] : [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.close-active-tab"),
scope: "window"
2019-11-18 23:01:31 +01:00
},
{
actionName: "reopenLastTab",
defaultShortcuts: isElectron ? ["CommandOrControl+Shift+T"] : [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.reopen-last-tab"),
scope: "window"
},
2019-11-18 23:01:31 +01:00
{
2020-02-19 20:54:14 +01:00
actionName: "activateNextTab",
defaultShortcuts: isElectron ? ["CommandOrControl+Tab", "CommandOrControl+PageDown"] : [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.activate-next-tab"),
scope: "window"
2019-11-21 22:24:07 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "activatePreviousTab",
defaultShortcuts: isElectron ? ["CommandOrControl+Shift+Tab", "CommandOrControl+PageUp"] : [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.activate-previous-tab"),
scope: "window"
2019-11-21 22:24:07 +01:00
},
{
actionName: "openNewWindow",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.open-new-window"),
scope: "window"
},
{
actionName: "toggleTray",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.toggle-tray"),
scope: "window"
},
2023-09-08 22:53:21 -04:00
{
actionName: "firstTab",
defaultShortcuts: ["CommandOrControl+1"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.first-tab"),
2023-09-11 18:03:49 -04:00
scope: "window"
2023-09-08 22:53:21 -04:00
},
{
actionName: "secondTab",
defaultShortcuts: ["CommandOrControl+2"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.second-tab"),
2023-09-11 18:03:49 -04:00
scope: "window"
2023-09-08 22:53:21 -04:00
},
{
actionName: "thirdTab",
defaultShortcuts: ["CommandOrControl+3"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.third-tab"),
2023-09-11 18:03:49 -04:00
scope: "window"
2023-09-08 22:53:21 -04:00
},
{
actionName: "fourthTab",
defaultShortcuts: ["CommandOrControl+4"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.fourth-tab"),
2023-09-11 18:03:49 -04:00
scope: "window"
2023-09-08 22:53:21 -04:00
},
{
actionName: "fifthTab",
defaultShortcuts: ["CommandOrControl+5"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.fifth-tab"),
2023-09-11 18:03:49 -04:00
scope: "window"
2023-09-08 22:53:21 -04:00
},
{
actionName: "sixthTab",
defaultShortcuts: ["CommandOrControl+6"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.sixth-tab"),
2023-09-11 18:03:49 -04:00
scope: "window"
2023-09-08 22:53:21 -04:00
},
{
actionName: "seventhTab",
defaultShortcuts: ["CommandOrControl+7"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.seventh-tab"),
2023-09-11 18:03:49 -04:00
scope: "window"
2023-09-08 22:53:21 -04:00
},
{
actionName: "eigthTab",
defaultShortcuts: ["CommandOrControl+8"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.eight-tab"),
2023-09-11 18:03:49 -04:00
scope: "window"
2023-09-08 22:53:21 -04:00
},
{
actionName: "ninthTab",
defaultShortcuts: ["CommandOrControl+9"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.ninth-tab"),
2023-09-11 18:03:49 -04:00
scope: "window"
2023-09-08 22:53:21 -04:00
},
{
actionName: "lastTab",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.last-tab"),
2023-09-11 18:03:49 -04:00
scope: "window"
2023-09-08 22:53:21 -04:00
},
2019-11-21 22:24:07 +01:00
{
2024-09-08 15:33:06 +03:00
separator: t("keyboard_actions.dialogs")
2019-11-18 23:01:31 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "showNoteSource",
2019-11-24 22:15:33 +01:00
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.show-note-source"),
scope: "window"
2019-11-18 23:01:31 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "showOptions",
2019-11-24 22:15:33 +01:00
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.show-options"),
scope: "window"
},
{
actionName: "showRevisions",
2019-11-24 22:15:33 +01:00
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.show-revisions"),
scope: "window"
},
{
2020-02-19 20:54:14 +01:00
actionName: "showRecentChanges",
2019-11-24 22:15:33 +01:00
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.show-recent-changes"),
scope: "window"
2019-11-18 23:01:31 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "showSQLConsole",
2019-11-24 22:15:33 +01:00
defaultShortcuts: ["Alt+O"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.show-sql-console"),
scope: "window"
2019-11-18 23:01:31 +01:00
},
2019-12-05 21:25:36 +01:00
{
2020-02-19 20:54:14 +01:00
actionName: "showBackendLog",
2019-12-05 21:25:36 +01:00
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.show-backend-log"),
scope: "window"
2019-12-05 21:25:36 +01:00
},
2019-11-18 23:01:31 +01:00
{
2023-02-17 16:44:04 +01:00
actionName: "showHelp",
2019-11-24 22:15:33 +01:00
defaultShortcuts: ["F1"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.show-help"),
scope: "window"
},
{
2024-09-08 15:33:06 +03:00
separator: t("keyboard_actions.text-note-operations")
},
{
2020-02-19 20:54:14 +01:00
actionName: "addLinkToText",
defaultShortcuts: ["CommandOrControl+L"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.add-link-to-text"),
scope: "text-detail"
2019-11-18 23:01:31 +01:00
},
{
actionName: "followLinkUnderCursor",
defaultShortcuts: ["CommandOrControl+Enter"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.follow-link-under-cursor"),
scope: "text-detail"
},
2019-11-18 23:01:31 +01:00
{
2020-02-19 20:54:14 +01:00
actionName: "insertDateTimeToText",
defaultShortcuts: ["Alt+T"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.insert-date-and-time-to-text"),
scope: "text-detail"
2019-11-18 23:01:31 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "pasteMarkdownIntoText",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.paste-markdown-into-text"),
scope: "text-detail"
},
2020-01-01 22:59:51 +01:00
{
2020-02-19 20:54:14 +01:00
actionName: "cutIntoNote",
2020-01-01 22:59:51 +01:00
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.cut-into-note"),
scope: "text-detail"
2020-01-01 22:59:51 +01:00
},
{
actionName: "addIncludeNoteToText",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.add-include-note-to-text"),
scope: "text-detail"
},
{
actionName: "editReadOnlyNote",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.edit-readonly-note"),
scope: "window"
},
{
2024-09-08 15:33:06 +03:00
separator: t("keyboard_actions.attributes-labels-and-relations")
},
{
actionName: "addNewLabel",
defaultShortcuts: ["Alt+L"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.add-new-label"),
scope: "window"
},
{
actionName: "addNewRelation",
defaultShortcuts: ["Alt+R"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.create-new-relation"),
scope: "window"
},
2021-06-27 12:53:05 +02:00
{
2024-09-08 15:33:06 +03:00
separator: t("keyboard_actions.ribbon-tabs")
2021-06-27 12:53:05 +02:00
},
{
actionName: "toggleRibbonTabBasicProperties",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.toggle-basic-properties"),
2021-06-27 12:53:05 +02:00
scope: "window"
},
{
actionName: "toggleRibbonTabBookProperties",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.toggle-book-properties"),
2021-06-27 12:53:05 +02:00
scope: "window"
},
{
actionName: "toggleRibbonTabFileProperties",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.toggle-file-properties"),
2021-06-27 12:53:05 +02:00
scope: "window"
},
{
actionName: "toggleRibbonTabImageProperties",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.toggle-image-properties"),
2021-06-27 12:53:05 +02:00
scope: "window"
},
{
actionName: "toggleRibbonTabOwnedAttributes",
defaultShortcuts: ["Alt+A"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.toggle-owned-attributes"),
2021-06-27 12:53:05 +02:00
scope: "window"
},
{
actionName: "toggleRibbonTabInheritedAttributes",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.toggle-inherited-attributes"),
2021-06-27 12:53:05 +02:00
scope: "window"
},
{
actionName: "toggleRibbonTabPromotedAttributes",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.toggle-promoted-attributes"),
2021-06-27 12:53:05 +02:00
scope: "window"
},
{
actionName: "toggleRibbonTabNoteMap",
2021-06-27 12:53:05 +02:00
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.toggle-link-map"),
2021-06-27 12:53:05 +02:00
scope: "window"
},
{
actionName: "toggleRibbonTabNoteInfo",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.toggle-note-info"),
2021-06-27 12:53:05 +02:00
scope: "window"
},
{
actionName: "toggleRibbonTabNotePaths",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.toggle-note-paths"),
2021-06-27 12:53:05 +02:00
scope: "window"
},
{
actionName: "toggleRibbonTabSimilarNotes",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.toggle-similar-notes"),
2021-06-27 12:53:05 +02:00
scope: "window"
},
{
2024-09-08 15:33:06 +03:00
separator: t("keyboard_actions.other")
},
{
actionName: "toggleRightPane",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.toggle-right-pane"),
scope: "window"
},
{
2020-02-19 20:54:14 +01:00
actionName: "printActiveNote",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.print-active-note"),
scope: "window"
},
{
actionName: "openNoteExternally",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.open-note-externally"),
scope: "window"
},
{
actionName: "renderActiveNote",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.render-active-note"),
scope: "window"
},
{
2020-02-19 20:54:14 +01:00
actionName: "runActiveNote",
defaultShortcuts: ["CommandOrControl+Enter"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.run-active-note"),
scope: "code-detail"
},
{
2020-02-19 20:54:14 +01:00
actionName: "toggleNoteHoisting",
defaultShortcuts: ["Alt+H"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.toggle-note-hoisting"),
scope: "window"
},
{
actionName: "unhoist",
defaultShortcuts: ["Alt+U"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.unhoist"),
scope: "window"
},
2019-11-18 23:01:31 +01:00
{
2020-02-19 20:54:14 +01:00
actionName: "reloadFrontendApp",
defaultShortcuts: ["F5", "CommandOrControl+R"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.reload-frontend-app"),
scope: "window"
2019-11-18 23:01:31 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "openDevTools",
defaultShortcuts: isElectron ? ["CommandOrControl+Shift+I"] : [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.open-dev-tools"),
scope: "window"
2019-11-18 23:01:31 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "findInText",
2020-09-13 00:19:50 +02:00
defaultShortcuts: isElectron ? ["CommandOrControl+F"] : [],
scope: "window"
2019-11-18 23:01:31 +01:00
},
{
actionName: "toggleLeftPane",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.toggle-left-note-tree-panel"),
scope: "window"
},
2019-11-18 23:01:31 +01:00
{
2020-02-19 20:54:14 +01:00
actionName: "toggleFullscreen",
defaultShortcuts: ["F11"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.toggle-full-screen"),
scope: "window"
2019-11-18 23:01:31 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "zoomOut",
2020-08-24 23:33:27 +02:00
defaultShortcuts: isElectron ? ["CommandOrControl+-"] : [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.zoom-out"),
scope: "window"
2019-11-18 23:01:31 +01:00
},
{
2020-02-19 20:54:14 +01:00
actionName: "zoomIn",
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.zoom-in"),
2020-08-24 23:33:27 +02:00
defaultShortcuts: isElectron ? ["CommandOrControl+="] : [],
scope: "window"
},
{
actionName: "zoomReset",
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.reset-zoom-level"),
defaultShortcuts: isElectron ? ["CommandOrControl+0"] : [],
scope: "window"
},
{
2020-02-19 20:54:14 +01:00
actionName: "copyWithoutFormatting",
defaultShortcuts: ["CommandOrControl+Alt+C"],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.copy-without-formatting"),
scope: "text-detail"
},
{
actionName: "forceSaveRevision",
defaultShortcuts: [],
2024-09-08 15:33:06 +03:00
description: t("keyboard_actions.force-save-revision"),
scope: "window"
}
2019-11-18 23:01:31 +01:00
];
2019-11-24 09:50:19 +01:00
const platformModifier = isMac ? 'Meta' : 'Ctrl';
2019-11-20 21:35:18 +01:00
2019-11-24 09:50:19 +01:00
for (const action of DEFAULT_KEYBOARD_ACTIONS) {
if (action.defaultShortcuts) {
action.defaultShortcuts = action.defaultShortcuts.map(shortcut => shortcut.replace("CommandOrControl", platformModifier));
2019-11-20 21:35:18 +01:00
}
2019-11-19 23:02:54 +01:00
}
2020-06-20 12:31:38 +02:00
function getKeyboardActions() {
2024-02-17 19:29:15 +02:00
const actions: KeyboardShortcut[] = JSON.parse(JSON.stringify(DEFAULT_KEYBOARD_ACTIONS));
2019-11-19 20:53:04 +01:00
for (const action of actions) {
2024-02-17 19:29:15 +02:00
action.effectiveShortcuts = action.defaultShortcuts ? action.defaultShortcuts.slice() : [];
2019-11-19 20:53:04 +01:00
}
2020-06-20 12:31:38 +02:00
for (const option of optionService.getOptions()) {
2019-11-19 20:53:04 +01:00
if (option.name.startsWith('keyboardShortcuts')) {
2024-04-03 19:22:49 +03:00
let actionName = option.name.substring(17);
2020-02-19 20:54:14 +01:00
actionName = actionName.charAt(0).toLowerCase() + actionName.slice(1);
2019-11-19 20:53:04 +01:00
const action = actions.find(ea => ea.actionName === actionName);
if (action) {
try {
action.effectiveShortcuts = JSON.parse(option.value);
}
catch (e) {
log.error(`Could not parse shortcuts for action ${actionName}`);
}
}
else {
log.info(`Keyboard action ${actionName} found in database, but not in action definition.`);
2019-11-19 20:53:04 +01:00
}
}
}
2019-11-19 23:02:54 +01:00
return actions;
2019-11-19 20:53:04 +01:00
}
export default {
2019-11-19 20:53:04 +01:00
DEFAULT_KEYBOARD_ACTIONS,
getKeyboardActions
2020-06-03 11:06:45 +02:00
};