make sure all keyboard shortcuts use utility methods to not break mobile frontend

This commit is contained in:
zadam 2019-08-12 22:41:53 +02:00
parent 493cd1a7e0
commit f30eec7737
10 changed files with 41 additions and 41 deletions

View File

@ -45,7 +45,7 @@ function showInFullText(e) {
$showInFullTextButton.click(showInFullText);
$dialog.bind('keydown', 'ctrl+return', showInFullText);
utils.bindElShortcut($dialog, 'ctrl+return', showInFullText);
export default {
showDialog

View File

@ -53,7 +53,7 @@ async function sendForm() {
$importButton.click(sendForm);
$dialog.bind('keydown', 'ctrl+return', sendForm);
utils.bindElShortcut($dialog, 'ctrl+return', sendForm);
// for CKEditor integration (button on block toolbar)
window.glob.importMarkdownInline = importMarkdownInline;

View File

@ -127,7 +127,7 @@ async function showTables() {
}
}
$query.bind('keydown', 'ctrl+return', execute);
utils.bindElShortcut($query, 'ctrl+return', execute);
$executeButton.click(execute);

View File

@ -23,11 +23,11 @@ function registerEntrypoints() {
jQuery.hotkeys.options.filterContentEditable = false;
jQuery.hotkeys.options.filterTextInputs = false;
utils.bindShortcut('ctrl+l', addLinkDialog.showDialog);
utils.bindShortcut('ctrl+shift+l', addLinkDialog.showDialogForClone);
utils.bindGlobalShortcut('ctrl+l', addLinkDialog.showDialog);
utils.bindGlobalShortcut('ctrl+shift+l', addLinkDialog.showDialogForClone);
$("#jump-to-note-dialog-button").click(jumpToNoteDialog.showDialog);
utils.bindShortcut('ctrl+j', jumpToNoteDialog.showDialog);
utils.bindGlobalShortcut('ctrl+j', jumpToNoteDialog.showDialog);
$("#recent-changes-button").click(recentChangesDialog.showDialog);
@ -35,11 +35,11 @@ function registerEntrypoints() {
$("#leave-protected-session-button").click(protectedSessionService.leaveProtectedSession);
$("#toggle-search-button").click(searchNotesService.toggleSearch);
utils.bindShortcut('ctrl+s', searchNotesService.toggleSearch);
utils.bindGlobalShortcut('ctrl+s', searchNotesService.toggleSearch);
const $noteTabContainer = $("#note-tab-container");
$noteTabContainer.on("click", ".show-attributes-button", attributesDialog.showDialog);
utils.bindShortcut('alt+a', attributesDialog.showDialog);
utils.bindGlobalShortcut('alt+a', attributesDialog.showDialog);
$noteTabContainer.on("click", ".show-note-info-button", noteInfoDialog.showDialog);
@ -66,10 +66,10 @@ function registerEntrypoints() {
$("#options-button").click(optionsDialog.showDialog);
$("#show-help-button").click(helpDialog.showDialog);
utils.bindShortcut('f1', helpDialog.showDialog);
utils.bindGlobalShortcut('f1', helpDialog.showDialog);
$("#open-sql-console-button").click(sqlConsoleDialog.showDialog);
utils.bindShortcut('alt+o', sqlConsoleDialog.showDialog);
utils.bindGlobalShortcut('alt+o', sqlConsoleDialog.showDialog);
$("#show-about-dialog-button").click(aboutDialog.showDialog);
@ -80,32 +80,32 @@ function registerEntrypoints() {
if (utils.isMac()) {
// Mac has a different history navigation shortcuts - https://github.com/zadam/trilium/issues/376
utils.bindShortcut('meta+left', window.history.back);
utils.bindShortcut('meta+right', window.history.forward);
utils.bindGlobalShortcut('meta+left', window.history.back);
utils.bindGlobalShortcut('meta+right', window.history.forward);
}
else {
utils.bindShortcut('alt+left', window.history.back);
utils.bindShortcut('alt+right', window.history.forward);
utils.bindGlobalShortcut('alt+left', window.history.back);
utils.bindGlobalShortcut('alt+right', window.history.forward);
}
}
utils.bindShortcut('alt+m', e => {
utils.bindGlobalShortcut('alt+m', e => {
$(".hide-toggle").toggle();
$("#container").toggleClass("distraction-free-mode");
});
// hide (toggle) everything except for the note content for distraction free writing
utils.bindShortcut('alt+t', e => {
utils.bindGlobalShortcut('alt+t', e => {
const date = new Date();
const dateString = utils.formatDateTime(date);
linkService.addTextToEditor(dateString);
});
utils.bindShortcut('f5', utils.reloadApp);
utils.bindGlobalShortcut('f5', utils.reloadApp);
$("#reload-frontend-button").click(utils.reloadApp);
utils.bindShortcut('ctrl+r', utils.reloadApp);
utils.bindGlobalShortcut('ctrl+r', utils.reloadApp);
$("#open-dev-tools-button").toggle(utils.isElectron());
@ -116,7 +116,7 @@ function registerEntrypoints() {
return false;
};
utils.bindShortcut('ctrl+shift+i', openDevTools);
utils.bindGlobalShortcut('ctrl+shift+i', openDevTools);
$("#open-dev-tools-button").click(openDevTools);
}
@ -141,7 +141,7 @@ function registerEntrypoints() {
}
if (utils.isElectron()) {
utils.bindShortcut('ctrl+f', () => {
utils.bindGlobalShortcut('ctrl+f', () => {
findInPage.openFindWindow();
return false;
@ -161,7 +161,7 @@ function registerEntrypoints() {
$("#toggle-fullscreen-button").click(toggleFullscreen);
utils.bindShortcut('f11', toggleFullscreen);
utils.bindGlobalShortcut('f11', toggleFullscreen);
}
else {
// outside of electron this is handled by the browser
@ -169,8 +169,8 @@ function registerEntrypoints() {
}
if (utils.isElectron()) {
utils.bindShortcut('ctrl+-', zoomService.decreaseZoomFactor);
utils.bindShortcut('ctrl+=', zoomService.increaseZoomFactor);
utils.bindGlobalShortcut('ctrl+-', zoomService.decreaseZoomFactor);
utils.bindGlobalShortcut('ctrl+=', zoomService.increaseZoomFactor);
}
}

View File

@ -95,7 +95,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte
}
if (opts.shortcut) {
$(document).bind('keydown', opts.shortcut, opts.action);
utils.bindGlobalShortcut(opts.shortcut, opts.action);
button.attr("title", "Shortcut " + opts.shortcut);
}

View File

@ -5,12 +5,12 @@ import utils from "./utils.js";
function init() {
if (utils.isElectron() && utils.isMac()) {
utils.bindShortcut('meta+c', () => exec("copy"));
utils.bindShortcut('meta+v', () => exec('paste'));
utils.bindShortcut('meta+x', () => exec('cut'));
utils.bindShortcut('meta+a', () => exec('selectAll'));
utils.bindShortcut('meta+z', () => exec('undo'));
utils.bindShortcut('meta+y', () => exec('redo'));
utils.bindGlobalShortcut('meta+c', () => exec("copy"));
utils.bindGlobalShortcut('meta+v', () => exec('paste'));
utils.bindGlobalShortcut('meta+x', () => exec('cut'));
utils.bindGlobalShortcut('meta+a', () => exec('selectAll'));
utils.bindGlobalShortcut('meta+z', () => exec('undo'));
utils.bindGlobalShortcut('meta+y', () => exec('redo'));
}
}

View File

@ -457,17 +457,17 @@ $(tabRow.el).on('contextmenu', '.note-tab', e => {
});
if (utils.isElectron()) {
utils.bindShortcut('ctrl+t', () => {
utils.bindGlobalShortcut('ctrl+t', () => {
openEmptyTab();
});
utils.bindShortcut('ctrl+w', () => {
utils.bindGlobalShortcut('ctrl+w', () => {
if (tabRow.activeTabEl) {
tabRow.removeTab(tabRow.activeTabEl);
}
});
utils.bindShortcut('ctrl+tab', () => {
utils.bindGlobalShortcut('ctrl+tab', () => {
const nextTab = tabRow.nextTabEl;
if (nextTab) {
@ -475,7 +475,7 @@ if (utils.isElectron()) {
}
});
utils.bindShortcut('ctrl+shift+tab', () => {
utils.bindGlobalShortcut('ctrl+shift+tab', () => {
const prevTab = tabRow.previousTabEl;
if (prevTab) {

View File

@ -83,7 +83,7 @@ class TabContext {
if (utils.isDesktop()) {
// keyboard plugin is not loaded in mobile
this.$noteTitle.bind('keydown', 'return', () => {
utils.bindElShortcut(this.$noteTitle, 'return', () => {
this.getComponent().focus();
return false; // to not propagate the enter into the editor (causes issues with codemirror)

View File

@ -769,7 +769,7 @@ messagingService.subscribeToSyncMessages(syncData => {
}
});
utils.bindShortcut('ctrl+o', async () => {
utils.bindGlobalShortcut('ctrl+o', async () => {
const node = getActiveNode();
const parentNoteId = node.data.parentNoteId;
const isProtected = await treeUtils.getParentProtectedStatus(node);
@ -815,9 +815,9 @@ async function reloadNote(noteId) {
window.glob.createNoteInto = createNoteInto;
utils.bindShortcut('ctrl+p', createNoteInto);
utils.bindGlobalShortcut('ctrl+p', createNoteInto);
utils.bindShortcut('ctrl+.', scrollToActiveNote);
utils.bindGlobalShortcut('ctrl+.', scrollToActiveNote);
$(window).bind('hashchange', async function() {
if (isNotePathInAddress()) {
@ -845,7 +845,7 @@ $tree.on('mousedown', '.fancytree-title', e => {
}
});
utils.bindShortcut('alt+c', () => collapseTree()); // don't use shortened form since collapseTree() accepts argument
utils.bindGlobalShortcut('alt+c', () => collapseTree()); // don't use shortened form since collapseTree() accepts argument
$collapseTreeButton.click(() => collapseTree());
$createTopLevelNoteButton.click(createNewTopLevelNote);

View File

@ -129,7 +129,7 @@ function randomString(len) {
return text;
}
function bindShortcut(keyboardShortcut, handler) {
function bindGlobalShortcut(keyboardShortcut, handler) {
bindElShortcut($(document), keyboardShortcut, handler);
}
@ -221,7 +221,7 @@ export default {
download,
toObject,
randomString,
bindShortcut,
bindGlobalShortcut,
bindElShortcut,
isMobile,
isDesktop,