2019-11-19 20:53:04 +01:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const optionService = require('./options');
|
|
|
|
const log = require('./log');
|
|
|
|
|
2019-11-18 23:01:31 +01:00
|
|
|
const ELECTRON = "electron";
|
|
|
|
|
2019-11-19 20:53:04 +01:00
|
|
|
const DEFAULT_KEYBOARD_ACTIONS = [
|
2019-11-20 23:10:41 +01:00
|
|
|
{
|
|
|
|
separator: "Note navigation"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "BackInNoteHistory",
|
|
|
|
defaultShortcuts: ["Alt+Left"]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "ForwardInNoteHistory",
|
|
|
|
defaultShortcuts: ["Alt+Right"]
|
|
|
|
},
|
2019-11-18 23:01:31 +01:00
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "JumpToNote",
|
2019-11-20 21:35:18 +01:00
|
|
|
defaultShortcuts: ["Mod+J"],
|
2019-11-18 23:01:31 +01:00
|
|
|
description: 'Open "Jump to note" dialog'
|
|
|
|
},
|
2019-11-20 23:10:41 +01:00
|
|
|
|
|
|
|
|
2019-11-18 23:01:31 +01:00
|
|
|
{
|
2019-11-20 23:10:41 +01:00
|
|
|
separator: "Tabs"
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "NewTab",
|
2019-11-20 21:35:18 +01:00
|
|
|
defaultShortcuts: ["Mod+T"],
|
2019-11-18 23:01:31 +01:00
|
|
|
only: ELECTRON
|
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "CloseTab",
|
2019-11-20 21:35:18 +01:00
|
|
|
defaultShortcuts: ["Mod+W"],
|
2019-11-18 23:01:31 +01:00
|
|
|
only: ELECTRON
|
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "NextTab",
|
2019-11-20 21:35:18 +01:00
|
|
|
defaultShortcuts: ["Mod+Tab"],
|
2019-11-18 23:01:31 +01:00
|
|
|
only: ELECTRON
|
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "PreviousTab",
|
2019-11-20 23:10:41 +01:00
|
|
|
defaultShortcuts: ["Mod+Shift+Tab"],
|
2019-11-18 23:01:31 +01:00
|
|
|
only: ELECTRON
|
|
|
|
},
|
2019-11-20 23:10:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
separator: "Dialogs"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "ShowAttributes",
|
|
|
|
defaultShortcuts: ["Alt+A"]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "ShowNoteInfo",
|
|
|
|
defaultShortcuts: []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "ShowNoteSource",
|
|
|
|
defaultShortcuts: []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "ShowLinkMap",
|
|
|
|
defaultShortcuts: []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "ShowOptions",
|
|
|
|
defaultShortcuts: []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "ShowNoteRevisions",
|
|
|
|
defaultShortcuts: []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "ShowRecentChanges",
|
|
|
|
defaultShortcuts: []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "ShowHelp",
|
|
|
|
defaultShortcuts: ["F1"]
|
|
|
|
},
|
2019-11-18 23:01:31 +01:00
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "CreateNoteAfter",
|
2019-11-20 21:35:18 +01:00
|
|
|
defaultShortcuts: ["Mod+O"]
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "CreateNoteInto",
|
2019-11-20 21:35:18 +01:00
|
|
|
defaultShortcuts: ["Mod+P"]
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "ScrollToActiveNote",
|
2019-11-20 21:35:18 +01:00
|
|
|
defaultShortcuts: ["Mod+."]
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "CollapseTree",
|
2019-11-20 21:35:18 +01:00
|
|
|
defaultShortcuts: ["Alt+C"]
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "FocusNote",
|
2019-11-18 23:01:31 +01:00
|
|
|
defaultShortcuts: ["return"]
|
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "RunCurrentNote",
|
2019-11-20 21:35:18 +01:00
|
|
|
defaultShortcuts: ["Mod+return"]
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "ClipboardCopy",
|
2019-11-20 23:10:41 +01:00
|
|
|
defaultShortcuts: ["Mod+C"],
|
|
|
|
description: "Copy selected notes to the clipboard"
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "ClipboardPaste",
|
2019-11-20 23:10:41 +01:00
|
|
|
defaultShortcuts: ["Mod+V"],
|
|
|
|
description: "Paste notes from the clipboard into active note"
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "ClipboardCut",
|
2019-11-20 23:10:41 +01:00
|
|
|
defaultShortcuts: ["Mod+X"],
|
|
|
|
description: "Copy selected notes to the clipboard"
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "SelectAllNotesInParent",
|
2019-11-20 23:10:41 +01:00
|
|
|
defaultShortcuts: ["Mod+A"],
|
|
|
|
description: "Select all notes from the current note level"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
separator: "Text note operations"
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "Undo",
|
2019-11-20 23:10:41 +01:00
|
|
|
defaultShortcuts: ["Mod+Z"],
|
|
|
|
description: "Undo last text operation (applicable on MacOS only)"
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "Redo",
|
2019-11-20 23:10:41 +01:00
|
|
|
defaultShortcuts: ["Mod+Y"],
|
|
|
|
description: "Undo last text operation (applicable on MacOS only)"
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "AddLinkToText",
|
2019-11-20 23:10:41 +01:00
|
|
|
defaultShortcuts: ["Mod+L"],
|
|
|
|
description: "Open dialog to add link to the text"
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "CloneNotesTo",
|
2019-11-20 21:35:18 +01:00
|
|
|
defaultShortcuts: ["Mod+Shift+C"]
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "MoveNotesTo",
|
2019-11-20 21:35:18 +01:00
|
|
|
defaultShortcuts: ["Mod+Shift+C"]
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "SearchNotes",
|
2019-11-20 21:35:18 +01:00
|
|
|
defaultShortcuts: ["Mod+S"]
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 23:02:54 +01:00
|
|
|
actionName: "ShowSQLConsole",
|
2019-11-20 21:35:18 +01:00
|
|
|
defaultShortcuts: ["Alt+O"]
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-20 23:10:41 +01:00
|
|
|
actionName: "RunSQL",
|
|
|
|
defaultShortcuts: ["Mod+return"]
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "InsertDateTime",
|
2019-11-20 21:35:18 +01:00
|
|
|
defaultShortcuts: ["Alt+T"]
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "ReloadApp",
|
2019-11-20 21:35:18 +01:00
|
|
|
defaultShortcuts: ["F5", "Mod+R"]
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "OpenDevTools",
|
2019-11-20 23:10:41 +01:00
|
|
|
defaultShortcuts: ["Mod+Shift+I"]
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "FindInText",
|
2019-11-20 21:35:18 +01:00
|
|
|
defaultShortcuts: ["Mod+F"]
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "ToggleFullscreen",
|
2019-11-20 21:35:18 +01:00
|
|
|
defaultShortcuts: ["F11"]
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
2019-11-20 23:10:41 +01:00
|
|
|
{
|
|
|
|
actionName: "ToggleZenMode",
|
|
|
|
defaultShortcuts: ["Alt+M"]
|
|
|
|
},
|
2019-11-18 23:01:31 +01:00
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "ZoomOut",
|
2019-11-20 21:35:18 +01:00
|
|
|
defaultShortcuts: ["Mod+-"]
|
2019-11-18 23:01:31 +01:00
|
|
|
},
|
|
|
|
{
|
2019-11-19 20:53:04 +01:00
|
|
|
actionName: "ZoomIn",
|
2019-11-20 21:35:18 +01:00
|
|
|
defaultShortcuts: ["Mod+="]
|
2019-11-20 23:10:41 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "MarkdownToHTML",
|
|
|
|
defaultShortcuts: ["Mod+Return"]
|
|
|
|
},
|
2019-11-18 23:01:31 +01:00
|
|
|
];
|
|
|
|
|
2019-11-19 23:02:54 +01:00
|
|
|
if (process.platform === "darwin") {
|
2019-11-20 21:35:18 +01:00
|
|
|
for (const action of DEFAULT_KEYBOARD_ACTIONS) {
|
2019-11-20 23:10:41 +01:00
|
|
|
if (action.defaultShortcuts) {
|
|
|
|
action.defaultShortcuts = action.defaultShortcuts.map(shortcut => shortcut.replace("Mod", "Meta"));
|
|
|
|
}
|
2019-11-20 21:35:18 +01:00
|
|
|
}
|
|
|
|
|
2019-11-19 23:02:54 +01:00
|
|
|
// Mac has a different history navigation shortcuts - https://github.com/zadam/trilium/issues/376
|
2019-11-20 21:35:18 +01:00
|
|
|
DEFAULT_KEYBOARD_ACTIONS.find(ka => ka.actionName === 'BackInNoteHistory').defaultShortcuts = ["Meta+Left"];
|
|
|
|
DEFAULT_KEYBOARD_ACTIONS.find(ka => ka.actionName === 'ForwardInNoteHistory').defaultShortcuts = ["Meta+Right"];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (const action of DEFAULT_KEYBOARD_ACTIONS) {
|
2019-11-20 23:10:41 +01:00
|
|
|
if (action.defaultShortcuts) {
|
|
|
|
action.defaultShortcuts = action.defaultShortcuts.map(shortcut => shortcut.replace("Mod", "Ctrl"));
|
|
|
|
}
|
2019-11-20 21:35:18 +01:00
|
|
|
}
|
2019-11-19 23:02:54 +01:00
|
|
|
}
|
|
|
|
|
2019-11-19 20:53:04 +01:00
|
|
|
async function getKeyboardActions() {
|
|
|
|
const actions = JSON.parse(JSON.stringify(DEFAULT_KEYBOARD_ACTIONS));
|
|
|
|
|
|
|
|
for (const action of actions) {
|
2019-11-20 23:10:41 +01:00
|
|
|
if (action.defaultShortcuts) {
|
|
|
|
action.effectiveShortcuts = action.defaultShortcuts.slice();
|
|
|
|
}
|
2019-11-19 20:53:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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-19 23:02:54 +01:00
|
|
|
|
|
|
|
return actions;
|
2019-11-19 20:53:04 +01:00
|
|
|
}
|
|
|
|
|
2019-11-18 23:01:31 +01:00
|
|
|
module.exports = {
|
2019-11-19 20:53:04 +01:00
|
|
|
DEFAULT_KEYBOARD_ACTIONS,
|
|
|
|
getKeyboardActions
|
2019-11-18 23:01:31 +01:00
|
|
|
};
|