2019-11-20 03:53:04 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const optionService = require('./options');
|
|
|
|
const log = require('./log');
|
2019-11-24 16:50:19 +08:00
|
|
|
const utils = require('./utils');
|
2019-11-20 03:53:04 +08:00
|
|
|
|
2019-11-24 16:50:19 +08:00
|
|
|
const isMac = process.platform === "darwin";
|
|
|
|
const isElectron = utils.isElectron();
|
2019-11-19 06:01:31 +08:00
|
|
|
|
2019-11-20 03:53:04 +08:00
|
|
|
const DEFAULT_KEYBOARD_ACTIONS = [
|
2019-11-21 06:10:41 +08:00
|
|
|
{
|
|
|
|
separator: "Note navigation"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "BackInNoteHistory",
|
2019-11-24 16:50:19 +08:00
|
|
|
// Mac has a different history navigation shortcuts - https://github.com/zadam/trilium/issues/376
|
|
|
|
defaultShortcuts: isMac ? ["Meta+Left"] : ["Alt+Left"]
|
2019-11-21 06:10:41 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "ForwardInNoteHistory",
|
2019-11-24 16:50:19 +08:00
|
|
|
// Mac has a different history navigation shortcuts - https://github.com/zadam/trilium/issues/376
|
|
|
|
defaultShortcuts: isMac ? ["Meta+Right"] : ["Alt+Right"]
|
2019-11-21 06:10:41 +08:00
|
|
|
},
|
2019-11-19 06:01:31 +08:00
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "JumpToNote",
|
2019-11-22 04:12:07 +08:00
|
|
|
defaultShortcuts: ["CommandOrControl+J"],
|
2019-11-19 06:01:31 +08:00
|
|
|
description: 'Open "Jump to note" dialog'
|
|
|
|
},
|
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
actionName: "ScrollToActiveNote",
|
|
|
|
defaultShortcuts: ["CommandOrControl+."]
|
2019-11-21 06:10:41 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
actionName: "SearchNotes",
|
|
|
|
defaultShortcuts: ["CommandOrControl+S"]
|
2019-11-21 06:10:41 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
actionName: "SearchInSubtree",
|
|
|
|
defaultShortcuts: ["CommandOrControl+Shift+S"],
|
|
|
|
description: "Search for notes in the active note's subtree"
|
2019-11-21 06:10:41 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
actionName: "CollapseTree",
|
|
|
|
defaultShortcuts: ["Alt+C"]
|
2019-11-21 06:10:41 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
actionName: "CollapseSubtree",
|
|
|
|
defaultShortcuts: ["Alt+-"],
|
|
|
|
description: "Collapses subtree of current note"
|
2019-11-21 06:10:41 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
actionName: "ActivateParentNote",
|
|
|
|
defaultShortcuts: ["Backspace"],
|
2019-11-25 04:40:50 +08:00
|
|
|
description: "Activates the parent note of currently active note"
|
2019-11-21 06:10:41 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
actionName: "SortChildNotes",
|
|
|
|
defaultShortcuts: ["Alt+S"],
|
|
|
|
description: "Sort child notes"
|
2019-11-21 06:10:41 +08:00
|
|
|
},
|
2019-11-24 17:40:18 +08:00
|
|
|
|
|
|
|
|
2019-11-24 05:56:35 +08:00
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
separator: "Creating and moving notes"
|
2019-11-24 05:56:35 +08:00
|
|
|
},
|
2019-11-19 06:01:31 +08:00
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "CreateNoteAfter",
|
2019-11-22 04:12:07 +08:00
|
|
|
defaultShortcuts: ["CommandOrControl+O"]
|
2019-11-19 06:01:31 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "CreateNoteInto",
|
2019-11-22 04:12:07 +08:00
|
|
|
defaultShortcuts: ["CommandOrControl+P"]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "CreateNoteIntoDayNote",
|
|
|
|
defaultShortcuts: ["global:CommandOrControl+Alt+P"],
|
|
|
|
description: "Create and open subnote of a current day note"
|
2019-11-19 06:01:31 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-23 05:35:59 +08:00
|
|
|
actionName: "DeleteNotes",
|
2019-11-22 05:24:07 +08:00
|
|
|
defaultShortcuts: ["Delete"],
|
|
|
|
description: "Delete note"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "MoveNoteUp",
|
2019-11-24 05:17:08 +08:00
|
|
|
defaultShortcuts: ["CommandOrControl+Up"],
|
2019-11-22 05:24:07 +08:00
|
|
|
description: "Move note up"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "MoveNoteDown",
|
2019-11-24 05:17:08 +08:00
|
|
|
defaultShortcuts: ["CommandOrControl+Down"],
|
2019-11-22 05:24:07 +08:00
|
|
|
description: "Move note down"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "MoveNoteUpInHierarchy",
|
2019-11-24 05:17:08 +08:00
|
|
|
defaultShortcuts: ["CommandOrControl+Left"],
|
2019-11-22 05:24:07 +08:00
|
|
|
description: "Move note up in hierarchy"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "MoveNoteDownInHierarchy",
|
2019-11-24 05:17:08 +08:00
|
|
|
defaultShortcuts: ["CommandOrControl+Right"],
|
2019-11-22 05:24:07 +08:00
|
|
|
description: "Move note down in hierarchy"
|
|
|
|
},
|
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
actionName: "EditNoteTitle",
|
|
|
|
defaultShortcuts: ["Enter"],
|
2019-11-25 05:01:10 +08:00
|
|
|
description: "Jump from tree to the note detail and edit title"
|
2019-11-22 05:24:07 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
actionName: "EditBranchPrefix",
|
|
|
|
defaultShortcuts: ["F2"],
|
|
|
|
description: "Show Edit branch prefix dialog"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "CloneNotesTo",
|
|
|
|
defaultShortcuts: ["CommandOrControl+Shift+C"]
|
2019-11-22 05:24:07 +08:00
|
|
|
},
|
2019-11-24 17:40:18 +08:00
|
|
|
{
|
|
|
|
actionName: "MoveNotesTo",
|
2019-11-25 05:01:10 +08:00
|
|
|
defaultShortcuts: ["CommandOrControl+Shift+X"]
|
2019-11-24 17:40:18 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
separator: "Note clipboard"
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2019-11-22 05:24:07 +08:00
|
|
|
{
|
|
|
|
actionName: "CopyNotesToClipboard",
|
2019-11-22 04:12:07 +08:00
|
|
|
defaultShortcuts: ["CommandOrControl+C"],
|
2019-11-21 06:10:41 +08:00
|
|
|
description: "Copy selected notes to the clipboard"
|
2019-11-19 06:01:31 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-22 05:24:07 +08:00
|
|
|
actionName: "PasteNotesFromClipboard",
|
2019-11-22 04:12:07 +08:00
|
|
|
defaultShortcuts: ["CommandOrControl+V"],
|
2019-11-21 06:10:41 +08:00
|
|
|
description: "Paste notes from the clipboard into active note"
|
2019-11-19 06:01:31 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-22 05:24:07 +08:00
|
|
|
actionName: "CutNotesToClipboard",
|
2019-11-22 04:12:07 +08:00
|
|
|
defaultShortcuts: ["CommandOrControl+X"],
|
2019-11-22 05:24:07 +08:00
|
|
|
description: "Cut selected notes to the clipboard"
|
2019-11-19 06:01:31 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
actionName: "SelectAllNotesInParent",
|
|
|
|
defaultShortcuts: ["CommandOrControl+A"],
|
|
|
|
description: "Select all notes from the current note level"
|
2019-11-21 06:10:41 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
actionName: "AddNoteAboveToSelection",
|
|
|
|
defaultShortcuts: ["Shift+Up"],
|
|
|
|
description: "Add note above to the selection"
|
2019-11-22 05:24:07 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
actionName: "AddNoteBelowToSelection",
|
|
|
|
defaultShortcuts: ["Shift+Down"],
|
|
|
|
description: "Add note above to the selection"
|
2019-11-22 05:24:07 +08:00
|
|
|
},
|
2019-11-24 17:40:18 +08:00
|
|
|
|
|
|
|
|
2019-11-22 05:24:07 +08:00
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
separator: "Tabs"
|
2019-11-22 05:24:07 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
actionName: "OpenNewTab",
|
2019-11-25 05:15:33 +08:00
|
|
|
defaultShortcuts: isElectron ? ["CommandOrControl+T"] : [],
|
|
|
|
description: "Opens new tab"
|
2019-11-19 06:01:31 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
actionName: "CloseActiveTab",
|
2019-11-25 05:15:33 +08:00
|
|
|
defaultShortcuts: isElectron ? ["CommandOrControl+W"] : [],
|
|
|
|
description: "Closes active tab"
|
2019-11-19 06:01:31 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
actionName: "ActivateNextTab",
|
2019-11-25 05:15:33 +08:00
|
|
|
defaultShortcuts: isElectron ? ["CommandOrControl+Tab"] : [],
|
|
|
|
description: "Activates tab on the right"
|
2019-11-22 05:24:07 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
actionName: "ActivatePreviousTab",
|
2019-11-25 05:15:33 +08:00
|
|
|
defaultShortcuts: isElectron ? ["CommandOrControl+Shift+Tab"] : [],
|
|
|
|
description: "Activates tab on the left"
|
2019-11-22 05:24:07 +08:00
|
|
|
},
|
2019-11-24 17:40:18 +08:00
|
|
|
|
|
|
|
|
2019-11-22 05:24:07 +08:00
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
separator: "Dialogs"
|
2019-11-19 06:01:31 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
actionName: "ShowAttributes",
|
2019-11-25 05:15:33 +08:00
|
|
|
defaultShortcuts: ["Alt+A"],
|
|
|
|
description: "Shows Attributes dialog"
|
2019-11-19 06:01:31 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
actionName: "ShowNoteInfo",
|
2019-11-25 05:15:33 +08:00
|
|
|
defaultShortcuts: [],
|
|
|
|
description: "Shows Note Info dialog"
|
2019-11-19 06:01:31 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
actionName: "ShowNoteSource",
|
2019-11-25 05:15:33 +08:00
|
|
|
defaultShortcuts: [],
|
|
|
|
description: "Shows Note Source dialog"
|
2019-11-19 06:01:31 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
actionName: "ShowLinkMap",
|
2019-11-25 05:15:33 +08:00
|
|
|
defaultShortcuts: [],
|
|
|
|
description: "Shows Link Map dialog"
|
2019-11-24 17:40:18 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "ShowOptions",
|
2019-11-25 05:15:33 +08:00
|
|
|
defaultShortcuts: [],
|
|
|
|
description: "Shows Options dialog"
|
2019-11-24 17:40:18 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "ShowNoteRevisions",
|
2019-11-25 05:15:33 +08:00
|
|
|
defaultShortcuts: [],
|
|
|
|
description: "Shows Note Revisions dialog"
|
2019-11-24 17:40:18 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "ShowRecentChanges",
|
2019-11-25 05:15:33 +08:00
|
|
|
defaultShortcuts: [],
|
|
|
|
description: "Shows Recent Changes dialog"
|
2019-11-19 06:01:31 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-20 06:02:54 +08:00
|
|
|
actionName: "ShowSQLConsole",
|
2019-11-25 05:15:33 +08:00
|
|
|
defaultShortcuts: ["Alt+O"],
|
|
|
|
description: "Shows SQL Console dialog"
|
2019-11-19 06:01:31 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-24 17:40:18 +08:00
|
|
|
actionName: "ShowHelp",
|
2019-11-25 05:15:33 +08:00
|
|
|
defaultShortcuts: ["F1"],
|
|
|
|
description: "Shows built-in Help / cheatsheet"
|
2019-11-24 17:40:18 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
separator: "Text note operations"
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
actionName: "AddLinkToText",
|
|
|
|
defaultShortcuts: ["CommandOrControl+L"],
|
|
|
|
description: "Open dialog to add link to the text"
|
2019-11-19 06:01:31 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-24 05:17:08 +08:00
|
|
|
actionName: "InsertDateTimeToText",
|
2019-11-21 04:35:18 +08:00
|
|
|
defaultShortcuts: ["Alt+T"]
|
2019-11-19 06:01:31 +08:00
|
|
|
},
|
2019-11-24 17:40:18 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
separator: "Other"
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
actionName: "PrintActiveNote",
|
|
|
|
defaultShortcuts: []
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "RunActiveNote",
|
|
|
|
defaultShortcuts: ["CommandOrControl+Enter"],
|
|
|
|
description: "Run active JavaScript (frontend/backend) code note"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
actionName: "ToggleNoteHoisting",
|
|
|
|
defaultShortcuts: ["Alt+H"],
|
|
|
|
description: "Toggles note hoisting of active note"
|
|
|
|
},
|
2019-11-19 06:01:31 +08:00
|
|
|
{
|
2019-11-23 05:35:59 +08:00
|
|
|
actionName: "ReloadFrontendApp",
|
2019-11-22 04:12:07 +08:00
|
|
|
defaultShortcuts: ["F5", "CommandOrControl+R"]
|
2019-11-19 06:01:31 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "OpenDevTools",
|
2019-11-22 04:12:07 +08:00
|
|
|
defaultShortcuts: ["CommandOrControl+Shift+I"]
|
2019-11-19 06:01:31 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "FindInText",
|
2019-11-22 04:12:07 +08:00
|
|
|
defaultShortcuts: ["CommandOrControl+F"]
|
2019-11-19 06:01:31 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "ToggleFullscreen",
|
2019-11-21 04:35:18 +08:00
|
|
|
defaultShortcuts: ["F11"]
|
2019-11-19 06:01:31 +08:00
|
|
|
},
|
2019-11-21 06:10:41 +08:00
|
|
|
{
|
|
|
|
actionName: "ToggleZenMode",
|
|
|
|
defaultShortcuts: ["Alt+M"]
|
|
|
|
},
|
2019-11-19 06:01:31 +08:00
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "ZoomOut",
|
2019-11-22 04:12:07 +08:00
|
|
|
defaultShortcuts: ["CommandOrControl+-"]
|
2019-11-19 06:01:31 +08:00
|
|
|
},
|
|
|
|
{
|
2019-11-20 03:53:04 +08:00
|
|
|
actionName: "ZoomIn",
|
2019-11-22 04:12:07 +08:00
|
|
|
defaultShortcuts: ["CommandOrControl+="]
|
2019-11-24 05:56:35 +08:00
|
|
|
}
|
2019-11-19 06:01:31 +08:00
|
|
|
];
|
|
|
|
|
2019-11-24 16:50:19 +08:00
|
|
|
const platformModifier = isMac ? 'Meta' : 'Ctrl';
|
2019-11-21 04:35:18 +08:00
|
|
|
|
2019-11-24 16:50:19 +08:00
|
|
|
for (const action of DEFAULT_KEYBOARD_ACTIONS) {
|
|
|
|
if (action.defaultShortcuts) {
|
|
|
|
action.defaultShortcuts = action.defaultShortcuts.map(shortcut => shortcut.replace("CommandOrControl", platformModifier));
|
2019-11-21 04:35:18 +08:00
|
|
|
}
|
2019-11-20 06:02:54 +08:00
|
|
|
}
|
|
|
|
|
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) {
|
2019-11-21 06:10:41 +08:00
|
|
|
if (action.defaultShortcuts) {
|
|
|
|
action.effectiveShortcuts = action.defaultShortcuts.slice();
|
|
|
|
}
|
2019-11-20 03:53:04 +08: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 {
|
2019-11-24 05:56:35 +08:00
|
|
|
log.info(`Keyboard action ${actionName} found in database, but not in action definition.`);
|
2019-11-20 03:53:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
};
|