From 79dcf0b46c4ea124e8a7849e4b82c08355ebb7fe Mon Sep 17 00:00:00 2001 From: David Manthey Date: Tue, 28 Feb 2017 11:33:53 -0500 Subject: [PATCH] Make it easier to disable or replace keyboard actions. If keyboard.actions is specified in the interactor constructor, replace the set of keyboard actions rather than modify it. Otherwise, it is too annoying to disable or replace. --- src/mapInteractor.js | 5 ++++- tests/cases/mapInteractor.js | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/mapInteractor.js b/src/mapInteractor.js index a476482469..5f98eabe80 100644 --- a/src/mapInteractor.js +++ b/src/mapInteractor.js @@ -152,7 +152,7 @@ var mapInteractor = function (args) { keyboard: { actions: { /* Specific actions can be disabled by removing them from this object - * or stting an empty list as the key bindings. Additional actions + * or setting an empty list as the key bindings. Additional actions * can be added to the dictionary, each of which gets a list of key * bindings. See Mousetrap documentation for special key names. */ 'zoom.in': ['plus', 'shift+plus', 'shift+ctrl+plus', '=', 'shift+=', 'shift+ctrl+='], @@ -225,6 +225,9 @@ var mapInteractor = function (args) { if (args && args.momentum && args.momentum.actions) { m_options.momentum.actions = $.extend(true, [], args.momentum.actions); } + if (args && args.keyboard && args.keyboard.actions !== undefined) { + m_options.keyboard.actions = $.extend(true, {}, args.keyboard.actions); + } // options supported: // { diff --git a/tests/cases/mapInteractor.js b/tests/cases/mapInteractor.js index 133dbd5659..066e474d9e 100644 --- a/tests/cases/mapInteractor.js +++ b/tests/cases/mapInteractor.js @@ -1681,5 +1681,14 @@ describe('mapInteractor', function () { keyboardSettings.focusHighlight = true; expect(interactor.keyboard(keyboardSettings)).toBe(interactor); expect(map.node().hasClass('highlight-focus')).toBe(true); + + // test creating a interactor with a different set of keyboard actions + interactor = geo.mapInteractor({map: map, keyboard: {actions: {'zoom.0': ['1']}}}); + triggered = 0; + interactor.simulateEvent('keyboard', {keys: '1'}); + expect(triggered).toBe(1); + triggered = 0; + interactor.simulateEvent('keyboard', {keys: '2'}); + expect(triggered).toBe(0); }); });