2019-11-20 03:53:04 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const optionService = require('./options');
|
2019-11-20 06:02:54 +08:00
|
|
|
const utils = require('./utils');
|
2019-11-20 03:53:04 +08:00
|
|
|
const log = require('./log');
|
|
|
|
|
2019-11-19 06:01:31 +08:00
|
|
|
const ELECTRON = "electron";
|
|
|
|
|
2019-11-20 03:53:04 +08:00
|
|
|
const DEFAULT_KEYBOARD_ACTIONS = [
|
2019-11-19 06:01:31 +08:00
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "JumpToNote",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+j"],
|
|
|
|
description: 'Open "Jump to note" dialog'
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "MarkdownToHTML",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+return"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "NewTab",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+t"],
|
|
|
|
only: ELECTRON
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "CloseTab",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+w"],
|
|
|
|
only: ELECTRON
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "NextTab",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+tab"],
|
|
|
|
only: ELECTRON
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "PreviousTab",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+shift+tab"],
|
|
|
|
only: ELECTRON
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "CreateNoteAfter",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+o"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "CreateNoteInto",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+p"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "ScrollToActiveNote",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+."]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "CollapseTree",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["alt+c"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "RunSQL",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+return"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "FocusNote",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["return"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "RunCurrentNote",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+return"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "ClipboardCopy",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+c"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "ClipboardPaste",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+v"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "ClipboardCut",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+x"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "SelectAllNotesInParent",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+a"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "Undo",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+z"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "Redo",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+y"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "AddLinkToText",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+l"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "CloneNotesTo",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+shift+c"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "MoveNotesTo",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+shift+c"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "SearchNotes",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+s"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "ShowAttributes",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["alt+a"]
|
|
|
|
},
|
2019-11-20 06:02:54 +08:00
|
|
|
{
|
|
|
|
actionName: "ShowNoteInfo",
|
|
|
|
defaultShortcuts: []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "ShowNoteSource",
|
|
|
|
defaultShortcuts: []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "ShowLinkMap",
|
|
|
|
defaultShortcuts: []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "ShowOptions",
|
|
|
|
defaultShortcuts: []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "ShowNoteRevisions",
|
|
|
|
defaultShortcuts: []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "ShowRecentChanges",
|
|
|
|
defaultShortcuts: []
|
|
|
|
},
|
2019-11-19 06:01:31 +08:00
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "ShowHelp",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["f1"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 06:02:54 +08:00
|
|
|
actionName: "ShowSQLConsole",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["alt+o"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "BackInNoteHistory",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["alt+left"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "ForwardInNoteHistory",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["alt+right"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "ToggleZenMode",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["alt+m"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "InsertDateTime",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["alt+t"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "ReloadApp",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["f5", "mod+r"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "OpenDevTools",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+shift+i"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "FindInText",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+f"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "ToggleFullscreen",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["f11"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "ZoomOut",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+-"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "ZoomIn",
|
2019-11-19 06:01:31 +08:00
|
|
|
defaultShortcuts: ["mod+="]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2019-11-20 06:02:54 +08:00
|
|
|
if (process.platform === "darwin") {
|
|
|
|
// Mac has a different history navigation shortcuts - https://github.com/zadam/trilium/issues/376
|
|
|
|
DEFAULT_KEYBOARD_ACTIONS.find(ka => ka.actionName === 'BackInNoteHistory').defaultShortcuts = ["meta+left"];
|
|
|
|
DEFAULT_KEYBOARD_ACTIONS.find(ka => ka.actionName === 'ForwardInNoteHistory').defaultShortcuts = ["meta+right"];
|
|
|
|
}
|
|
|
|
|
2019-11-20 03:53:04 +08:00
|
|
|
async function getKeyboardActions() {
|
|
|
|
const actions = JSON.parse(JSON.stringify(DEFAULT_KEYBOARD_ACTIONS));
|
|
|
|
|
|
|
|
for (const action of actions) {
|
|
|
|
action.effectiveShortcuts = action.defaultShortcuts.slice();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const option of await optionService.getOptions()) {
|
|
|
|
if (option.name.startsWith('keyboardShortcuts')) {
|
|
|
|
const actionName = option.name.substr(17);
|
|
|
|
|
|
|
|
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} not found.`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-20 06:02:54 +08:00
|
|
|
|
|
|
|
return actions;
|
2019-11-20 03:53:04 +08:00
|
|
|
}
|
|
|
|
|
2019-11-19 06:01:31 +08:00
|
|
|
module.exports = {
|
2019-11-20 03:53:04 +08:00
|
|
|
DEFAULT_KEYBOARD_ACTIONS,
|
|
|
|
getKeyboardActions
|
2019-11-19 06:01:31 +08:00
|
|
|
};
|