binding remaining actions

This commit is contained in:
zadam 2019-11-24 09:50:19 +01:00
parent ff3f0ee0a0
commit d21e824343
3 changed files with 41 additions and 52 deletions

View File

@ -8,6 +8,7 @@ import utils from "./utils.js";
import contextMenuService from "./context_menu.js"; import contextMenuService from "./context_menu.js";
import treeUtils from "./tree_utils.js"; import treeUtils from "./tree_utils.js";
import tabRow from "./tab_row.js"; import tabRow from "./tab_row.js";
import keyboardActionService from "./keyboard_actions.js";
const $tabContentsContainer = $("#note-tab-container"); const $tabContentsContainer = $("#note-tab-container");
const $savedIndicator = $(".saved-indicator"); const $savedIndicator = $(".saved-indicator");
@ -419,33 +420,31 @@ $(tabRow.el).on('contextmenu', '.note-tab', e => {
}); });
}); });
if (utils.isElectron()) { keyboardActionService.setActionHandler('OpenNewTab', () => {
utils.bindGlobalShortcut('ctrl+t', () => { openEmptyTab();
openEmptyTab(); });
});
utils.bindGlobalShortcut('ctrl+w', () => { keyboardActionService.setActionHandler('CloseActiveTab', () => {
if (tabRow.activeTabEl) { if (tabRow.activeTabEl) {
tabRow.removeTab(tabRow.activeTabEl); tabRow.removeTab(tabRow.activeTabEl);
} }
}); });
utils.bindGlobalShortcut('ctrl+tab', () => { keyboardActionService.setActionHandler('ActivateNextTab', () => {
const nextTab = tabRow.nextTabEl; const nextTab = tabRow.nextTabEl;
if (nextTab) { if (nextTab) {
tabRow.activateTab(nextTab); tabRow.activateTab(nextTab);
} }
}); });
utils.bindGlobalShortcut('ctrl+shift+tab', () => { keyboardActionService.setActionHandler('ActivatePreviousTab', () => {
const prevTab = tabRow.previousTabEl; const prevTab = tabRow.previousTabEl;
if (prevTab) { if (prevTab) {
tabRow.activateTab(prevTab); tabRow.activateTab(prevTab);
} }
}); });
}
tabRow.addListener('activeTabChange', openTabsChanged); tabRow.addListener('activeTabChange', openTabsChanged);
tabRow.addListener('tabRemove', openTabsChanged); tabRow.addListener('tabRemove', openTabsChanged);

View File

@ -14,6 +14,7 @@ import hoistedNoteService from '../services/hoisted_note.js';
import optionsService from "../services/options.js"; import optionsService from "../services/options.js";
import TreeContextMenu from "./tree_context_menu.js"; import TreeContextMenu from "./tree_context_menu.js";
import bundle from "./bundle.js"; import bundle from "./bundle.js";
import keyboardActionService from "./keyboard_actions.js";
const $tree = $("#tree"); const $tree = $("#tree");
const $createTopLevelNoteButton = $("#create-top-level-note-button"); 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 node = getActiveNode();
const parentNoteId = node.data.parentNoteId; const parentNoteId = node.data.parentNoteId;
const isProtected = await treeUtils.getParentProtectedStatus(node); const isProtected = await treeUtils.getParentProtectedStatus(node);
@ -867,9 +868,9 @@ async function reloadNotes(noteIds, activateNotePath = null) {
window.glob.createNoteInto = createNoteInto; 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() { $(window).bind('hashchange', async function() {
if (isNotePathInAddress()) { 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()); $collapseTreeButton.on('click', () => collapseTree());
$createTopLevelNoteButton.on('click', createNewTopLevelNote); $createTopLevelNoteButton.on('click', createNewTopLevelNote);

View File

@ -2,8 +2,10 @@
const optionService = require('./options'); const optionService = require('./options');
const log = require('./log'); const log = require('./log');
const utils = require('./utils');
const ELECTRON = "electron"; const isMac = process.platform === "darwin";
const isElectron = utils.isElectron();
const DEFAULT_KEYBOARD_ACTIONS = [ const DEFAULT_KEYBOARD_ACTIONS = [
{ {
@ -11,11 +13,13 @@ const DEFAULT_KEYBOARD_ACTIONS = [
}, },
{ {
actionName: "BackInNoteHistory", 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", 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", actionName: "JumpToNote",
@ -29,23 +33,19 @@ const DEFAULT_KEYBOARD_ACTIONS = [
}, },
{ {
actionName: "OpenNewTab", actionName: "OpenNewTab",
defaultShortcuts: ["CommandOrControl+T"], defaultShortcuts: isElectron ? ["CommandOrControl+T"] : []
only: ELECTRON
}, },
{ {
actionName: "CloseActiveTab", actionName: "CloseActiveTab",
defaultShortcuts: ["CommandOrControl+W"], defaultShortcuts: isElectron ? ["CommandOrControl+W"] : []
only: ELECTRON
}, },
{ {
actionName: "ActivateNextTab", actionName: "ActivateNextTab",
defaultShortcuts: ["CommandOrControl+Tab"], defaultShortcuts: isElectron ? ["CommandOrControl+Tab"] : []
only: ELECTRON
}, },
{ {
actionName: "ActivatePreviousTab", actionName: "ActivatePreviousTab",
defaultShortcuts: ["CommandOrControl+Shift+Tab"], defaultShortcuts: isElectron ? ["CommandOrControl+Shift+Tab"] : []
only: ELECTRON
}, },
@ -269,22 +269,11 @@ const DEFAULT_KEYBOARD_ACTIONS = [
} }
]; ];
if (process.platform === "darwin") { const platformModifier = isMac ? 'Meta' : 'Ctrl';
for (const action of DEFAULT_KEYBOARD_ACTIONS) {
if (action.defaultShortcuts) {
action.defaultShortcuts = action.defaultShortcuts.map(shortcut => shortcut.replace("CommandOrControl", "Meta"));
}
}
// Mac has a different history navigation shortcuts - https://github.com/zadam/trilium/issues/376 for (const action of DEFAULT_KEYBOARD_ACTIONS) {
DEFAULT_KEYBOARD_ACTIONS.find(ka => ka.actionName === 'BackInNoteHistory').defaultShortcuts = ["Meta+Left"]; if (action.defaultShortcuts) {
DEFAULT_KEYBOARD_ACTIONS.find(ka => ka.actionName === 'ForwardInNoteHistory').defaultShortcuts = ["Meta+Right"]; action.defaultShortcuts = action.defaultShortcuts.map(shortcut => shortcut.replace("CommandOrControl", platformModifier));
}
else {
for (const action of DEFAULT_KEYBOARD_ACTIONS) {
if (action.defaultShortcuts) {
action.defaultShortcuts = action.defaultShortcuts.map(shortcut => shortcut.replace("CommandOrControl", "Ctrl"));
}
} }
} }