diff --git a/Packages/ohif-hotkeys/client/classes/HotkeysContext.js b/Packages/ohif-hotkeys/client/classes/HotkeysContext.js index 38a59e537..56cc60be3 100644 --- a/Packages/ohif-hotkeys/client/classes/HotkeysContext.js +++ b/Packages/ohif-hotkeys/client/classes/HotkeysContext.js @@ -34,6 +34,7 @@ export class HotkeysContext { const bind = hotkey => $(document).bind(bindingKey, hotkey, event => { if (!this.enabled.get()) return; OHIF.commands.run(command); + event.preventDefault(); }); if (hotkey instanceof Array) { diff --git a/Packages/ohif-hotkeys/client/components/form.js b/Packages/ohif-hotkeys/client/components/form.js index 90accbf94..7ef1a3109 100644 --- a/Packages/ohif-hotkeys/client/components/form.js +++ b/Packages/ohif-hotkeys/client/components/form.js @@ -1,25 +1,27 @@ import { Template } from 'meteor/templating'; +import { ReactiveVar } from 'meteor/reactive-var'; import { $ } from 'meteor/jquery'; import { _ } from 'meteor/underscore'; import { OHIF } from 'meteor/ohif:core'; Template.hotkeysForm.onCreated(() => { const instance = Template.instance(); + const { contextName } = instance.data; instance.api = { save() { - const { contextName } = instance.data; const form = instance.$('form').first().data('component'); const definitions = form.value(); const promise = OHIF.hotkeys.store(contextName, definitions); - promise.then(() => OHIF.ui.notifications.success({ - text: 'The keyboard shortcut preferences were successfully saved.' - })); + promise.then(() => { + const successMessage = 'The keyboard shortcut preferences were successfully saved.'; + OHIF.ui.notifications.success({ text: successMessage }); + OHIF.hotkeys.load(contextName).then(defs => instance.hotkeysDefinitions.set(defs)); + }); return promise; }, resetDefaults() { - const { contextName } = instance.data; const dialogOptions = { class: 'themed', title: 'Reset Keyboard Shortcuts', @@ -93,9 +95,13 @@ Template.hotkeysForm.onCreated(() => { '': [], ALT: ['SPACE'], SHIFT: [], - CTRL: ['F4', 'F5', 'F11', 'W', 'R', 'T', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'PAGEDOWN', 'PAGEUP'], + CTRL: ['F4', 'F5', 'F11', 'W', 'R', 'T', 'O', 'P', 'A', 'D', 'F', 'G', 'H', 'J', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'PAGEDOWN', 'PAGEUP'], 'CTRL+SHIFT': ['Q', 'W', 'R', 'T', 'P', 'A', 'H', 'V', 'B', 'N'] }; + + const hotkeysContext = OHIF.hotkeys.getContext(contextName) || {}; + instance.hotkeysDefinitions = new ReactiveVar(hotkeysContext.definitions); + OHIF.hotkeys.load(contextName).then(defs => instance.hotkeysDefinitions.set(defs)); }); Template.hotkeysForm.events({ @@ -201,11 +207,10 @@ Template.hotkeysForm.helpers({ const instance = Template.instance(); const { contextName } = instance.data; - const hotkeysContext = OHIF.hotkeys.getContext(contextName); + const hotkeyDefinitions = instance.hotkeysDefinitions.get(); const commandsContext = OHIF.commands.getContext(contextName); - if (!hotkeysContext || !commandsContext) return {}; + if (!hotkeyDefinitions || !commandsContext) return {}; - const hotkeyDefinitions = hotkeysContext.definitions; const commands = Object.keys(OHIF.hotkeys.defaults[contextName] || {}); const list = []; commands.forEach(commandName => {