From 0c383634068400a09fd9be141cab314b4e7a1a45 Mon Sep 17 00:00:00 2001 From: Quincy Morgan <2046746+quincylvania@users.noreply.github.com> Date: Mon, 5 Oct 2020 10:57:18 -0400 Subject: [PATCH] Don't instantiate uiShortcuts or its keybinding multiple times --- modules/ui/init.js | 4 +++- modules/ui/panes/help.js | 3 +-- modules/ui/shortcuts.js | 27 +++++++++++++-------------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/modules/ui/init.js b/modules/ui/init.js index 5345eb8a7..4d39bd75d 100644 --- a/modules/ui/init.js +++ b/modules/ui/init.js @@ -418,7 +418,7 @@ export function uiInit(context) { } context.container() - .call(uiShortcuts(context)); + .call(ui.shortcuts); } var osm = context.connection(); @@ -499,6 +499,8 @@ export function uiInit(context) { ui.photoviewer = uiPhotoviewer(context); + ui.shortcuts = uiShortcuts(context); + ui.onResize = function(withPan) { var map = context.map(); diff --git a/modules/ui/panes/help.js b/modules/ui/panes/help.js index b0a8649fb..7a03b5675 100644 --- a/modules/ui/panes/help.js +++ b/modules/ui/panes/help.js @@ -4,7 +4,6 @@ import { event as d3_event } from 'd3-selection'; import marked from 'marked'; import { svgIcon } from '../../svg/icon'; import { uiIntro } from '../intro/intro'; -import { uiShortcuts } from '../shortcuts'; import { uiPane } from '../pane'; import { t, localizer } from '../../core/localizer'; @@ -353,7 +352,7 @@ export function uiPaneHelp(context) { function clickShortcuts() { d3_event.preventDefault(); - context.container().call(uiShortcuts(context), true); + context.container().call(context.ui().shortcuts, true); } var toc = content diff --git a/modules/ui/shortcuts.js b/modules/ui/shortcuts.js index 2708e467b..e88a28c80 100644 --- a/modules/ui/shortcuts.js +++ b/modules/ui/shortcuts.js @@ -16,20 +16,6 @@ export function uiShortcuts(context) { var _selection = d3_select(null); - context.keybinding() - .on([t('shortcuts.toggle.key'), '?'], function () { - if (context.container().selectAll('.modal-shortcuts').size()) { // already showing - if (_modalSelection) { - _modalSelection.close(); - _modalSelection = null; - } - } else { - _modalSelection = uiModal(_selection); - _modalSelection.call(shortcutsModal); - } - }); - - function shortcutsModal(_modalSelection) { _modalSelection.select('.modal') .classed('modal-shortcuts', true); @@ -264,6 +250,19 @@ export function uiShortcuts(context) { if (show) { _modalSelection = uiModal(selection); _modalSelection.call(shortcutsModal); + } else { + context.keybinding() + .on([t('shortcuts.toggle.key'), '?'], function () { + if (context.container().selectAll('.modal-shortcuts').size()) { // already showing + if (_modalSelection) { + _modalSelection.close(); + _modalSelection = null; + } + } else { + _modalSelection = uiModal(_selection); + _modalSelection.call(shortcutsModal); + } + }); } }; }