diff --git a/src/public/javascripts/dialogs/options/keyboard_shortcuts.js b/src/public/javascripts/dialogs/options/keyboard_shortcuts.js index 8f55a9a20..5120f3a87 100644 --- a/src/public/javascripts/dialogs/options/keyboard_shortcuts.js +++ b/src/public/javascripts/dialogs/options/keyboard_shortcuts.js @@ -1,5 +1,5 @@ import server from "../../services/server.js"; -import optionsService from "../../services/options.js"; +import utils from "../../services/utils.js"; const TPL = `

Keyboard shortcuts

@@ -19,9 +19,9 @@ const TPL = `
- + - +
`; @@ -29,6 +29,8 @@ export default class KeyboardShortcutsOptions { constructor() { $("#options-keyboard-shortcuts").html(TPL); + $("#options-keyboard-shortcuts-reload-app").on("click", () => utils.reloadApp()); + const $table = $("#keyboard-shortcut-table tbody"); server.get('keyboard-actions').then(actions => { @@ -36,7 +38,11 @@ export default class KeyboardShortcutsOptions { const $tr = $("") .append($("").text(action.actionName)) .append($("").append( - $(``).val(action.effectiveShortcuts.join(", "))) + $(``) + .val(action.effectiveShortcuts.join(", ")) + .attr('data-keyboard-action-name', action.actionName) + .attr('data-default-keyboard-shortcuts', action.defaultShortcuts.join(", ")) + ) ) .append($("").text(action.defaultShortcuts.join(", "))) .append($("").text(action.description)); @@ -44,18 +50,37 @@ export default class KeyboardShortcutsOptions { $table.append($tr); } }); - } - async save() { - const enabledMimeTypes = []; + $table.on('change', 'input.form-control', e => { + const $input = $(e.target); + const actionName = $input.attr('data-keyboard-action-name'); + const shortcuts = $input.val() + .replace('+,', "+Comma") + .split(",") + .map(shortcut => shortcut.replace("+Comma", "+,")); - this.$mimeTypes.find("input:checked").each( - (i, el) => enabledMimeTypes.push($(el).attr("data-mime-type"))); + const opts = {}; + opts['keyboardShortcuts' + actionName] = JSON.stringify(shortcuts); - const opts = { codeNotesMimeTypes: JSON.stringify(enabledMimeTypes) }; + server.put('options', opts); + }); - await server.put('options', opts); + $("#options-keyboard-shortcuts-set-all-to-default").on('click', async () => { + const confirmDialog = await import('../confirm.js'); - await optionsService.reloadOptions(); + if (!await confirmDialog.confirm("Do you really want to reset all keyboard shortcuts to the default?")) { + return; + } + + $table.find('input.form-control').each(function() { + const defaultShortcuts = $(this).attr('data-default-keyboard-shortcuts'); + + if ($(this).val() !== defaultShortcuts) { + $(this) + .val(defaultShortcuts) + .trigger('change'); + } + }); + }); } } \ No newline at end of file diff --git a/src/public/javascripts/services/entrypoints.js b/src/public/javascripts/services/entrypoints.js index e533fc4fb..31e6ee6c5 100644 --- a/src/public/javascripts/services/entrypoints.js +++ b/src/public/javascripts/services/entrypoints.js @@ -153,7 +153,11 @@ function registerEntrypoints() { caseSelectedColor: 'var(--main-border-color)' }); - setActionHandler("FindInText", () => findInPage.openFindWindow()); + setActionHandler("FindInText", () => { + if (!glob.activeDialog || !glob.activeDialog.is(":visible")) { + findInPage.openFindWindow(); + } + }); } if (utils.isElectron()) { diff --git a/src/public/javascripts/services/utils.js b/src/public/javascripts/services/utils.js index 0d4e439d9..8d252f666 100644 --- a/src/public/javascripts/services/utils.js +++ b/src/public/javascripts/services/utils.js @@ -137,7 +137,10 @@ function bindGlobalShortcut(keyboardShortcut, handler) { function bindElShortcut($el, keyboardShortcut, handler) { if (isDesktop()) { - keyboardShortcut = keyboardShortcut.replace("mod", isMac() ? "meta" : "ctrl"); + keyboardShortcut = keyboardShortcut + .toLowerCase() + .replace("ctrl+alt", "alt+ctrl") + .replace("meta+alt", "alt+meta"); // alt needs to be first $el.bind('keydown', keyboardShortcut, e => { handler(e);