Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
binding remaining actions
zadamd21e824343c3
diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.jsindex 5c41515da7..343836e7da 100644--- a/src/public/javascripts/services/note_detail.js+++ b/src/public/javascripts/services/note_detail.js@@ -8,6 +8,7 @@ import utils from "./utils.js";import contextMenuService from "./context_menu.js";import treeUtils from "./tree_utils.js";import tabRow from "./tab_row.js";+import keyboardActionService from "./keyboard_actions.js";const $tabContentsContainer = $("#note-tab-container");const $savedIndicator = $(".saved-indicator");@@ -419,33 +420,31 @@ $(tabRow.el).on('contextmenu', '.note-tab', e => {});});-if (utils.isElectron()) {- utils.bindGlobalShortcut('ctrl+t', () => {- openEmptyTab();- });+keyboardActionService.setActionHandler('OpenNewTab', () => {+ openEmptyTab();+});- utils.bindGlobalShortcut('ctrl+w', () => {- if (tabRow.activeTabEl) {- tabRow.removeTab(tabRow.activeTabEl);- }- });+keyboardActionService.setActionHandler('CloseActiveTab', () => {+ if (tabRow.activeTabEl) {+ tabRow.removeTab(tabRow.activeTabEl);+ }+});- utils.bindGlobalShortcut('ctrl+tab', () => {- const nextTab = tabRow.nextTabEl;+keyboardActionService.setActionHandler('ActivateNextTab', () => {+ const nextTab = tabRow.nextTabEl;- if (nextTab) {- tabRow.activateTab(nextTab);- }- });+ if (nextTab) {+ tabRow.activateTab(nextTab);+ }+});- utils.bindGlobalShortcut('ctrl+shift+tab', () => {- const prevTab = tabRow.previousTabEl;+keyboardActionService.setActionHandler('ActivatePreviousTab', () => {+ const prevTab = tabRow.previousTabEl;- if (prevTab) {- tabRow.activateTab(prevTab);- }- });-}+ if (prevTab) {+ tabRow.activateTab(prevTab);+ }+});tabRow.addListener('activeTabChange', openTabsChanged);tabRow.addListener('tabRemove', openTabsChanged);diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.jsindex de8f8f67dc..c446f6793d 100644--- a/src/public/javascripts/services/tree.js+++ b/src/public/javascripts/services/tree.js@@ -14,6 +14,7 @@ import hoistedNoteService from '../services/hoisted_note.js';import optionsService from "../services/options.js";import TreeContextMenu from "./tree_context_menu.js";import bundle from "./bundle.js";+import keyboardActionService from "./keyboard_actions.js";const $tree = $("#tree");const $createTopLevelNoteButton = $("#create-top-level-note-button");@@ -795,7 +796,7 @@ ws.subscribeToOutsideSyncMessages(async syncData => {}});-utils.bindGlobalShortcut('ctrl+o', async () => {+keyboardActionService.setActionHandler('CreateNoteAfter', async () => {const node = getActiveNode();const parentNoteId = node.data.parentNoteId;const isProtected = await treeUtils.getParentProtectedStatus(node);@@ -867,9 +868,9 @@ async function reloadNotes(noteIds, activateNotePath = null) {window.glob.createNoteInto = createNoteInto;-utils.bindGlobalShortcut('ctrl+p', createNoteInto);+keyboardActionService.setActionHandler('CreateNoteInto', createNoteInto);-utils.bindGlobalShortcut('ctrl+.', scrollToActiveNote);+keyboardActionService.setActionHandler('ScrollToActiveNote', scrollToActiveNote);$(window).bind('hashchange', async function() {if (isNotePathInAddress()) {@@ -907,7 +908,7 @@ async function duplicateNote(noteId, parentNoteId) {}-utils.bindGlobalShortcut('alt+c', () => collapseTree()); // don't use shortened form since collapseTree() accepts argument+keyboardActionService.setActionHandler('CollapseTree', () => collapseTree()); // don't use shortened form since collapseTree() accepts argument$collapseTreeButton.on('click', () => collapseTree());$createTopLevelNoteButton.on('click', createNewTopLevelNote);diff --git a/src/services/keyboard_actions.js b/src/services/keyboard_actions.jsindex a26ca053fd..8de4f1d136 100644--- a/src/services/keyboard_actions.js+++ b/src/services/keyboard_actions.js@@ -2,8 +2,10 @@const optionService = require('./options');const log = require('./log');+const utils = require('./utils');-const ELECTRON = "electron";+const isMac = process.platform === "darwin";+const isElectron = utils.isElectron();const DEFAULT_KEYBOARD_ACTIONS = [{@@ -11,11 +13,13 @@ const DEFAULT_KEYBOARD_ACTIONS = [},{actionName: "BackInNoteHistory",- defaultShortcuts: ["Alt+Left"]+ // Mac has a different history navigation shortcuts - https://github.com/zadam/trilium/issues/376+ defaultShortcuts: isMac ? ["Meta+Left"] : ["Alt+Left"]},{actionName: "ForwardInNoteHistory",- defaultShortcuts: ["Alt+Right"]+ // Mac has a different history navigation shortcuts - https://github.com/zadam/trilium/issues/376+ defaultShortcuts: isMac ? ["Meta+Right"] : ["Alt+Right"]},{actionName: "JumpToNote",@@ -29,23 +33,19 @@ const DEFAULT_KEYBOARD_ACTIONS = [},{actionName: "OpenNewTab",- defaultShortcuts: ["CommandOrControl+T"],- only: ELECTRON+ defaultShortcuts: isElectron ? ["CommandOrControl+T"] : []},{actionName: "CloseActiveTab",- defaultShortcuts: ["CommandOrControl+W"],- only: ELECTRON+ defaultShortcuts: isElectron ? ["CommandOrControl+W"] : []},{actionName: "ActivateNextTab",- defaultShortcuts: ["CommandOrControl+Tab"],- only: ELECTRON+ defaultShortcuts: isElectron ? ["CommandOrControl+Tab"] : []},{actionName: "ActivatePreviousTab",- defaultShortcuts: ["CommandOrControl+Shift+Tab"],- only: ELECTRON+ defaultShortcuts: isElectron ? ["CommandOrControl+Shift+Tab"] : []},@@ -269,22 +269,11 @@ const DEFAULT_KEYBOARD_ACTIONS = [}];-if (process.platform === "darwin") {- for (const action of DEFAULT_KEYBOARD_ACTIONS) {- if (action.defaultShortcuts) {- action.defaultShortcuts = action.defaultShortcuts.map(shortcut => shortcut.replace("CommandOrControl", "Meta"));- }- }+const platformModifier = isMac ? 'Meta' : 'Ctrl';- // 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"];-}-else {- for (const action of DEFAULT_KEYBOARD_ACTIONS) {- if (action.defaultShortcuts) {- action.defaultShortcuts = action.defaultShortcuts.map(shortcut => shortcut.replace("CommandOrControl", "Ctrl"));- }+for (const action of DEFAULT_KEYBOARD_ACTIONS) {+ if (action.defaultShortcuts) {+ action.defaultShortcuts = action.defaultShortcuts.map(shortcut => shortcut.replace("CommandOrControl", platformModifier));}}