From 08530dd822095f65898e5eb1c80e318a4f04430e Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Thu, 3 Oct 2019 16:57:12 +0200 Subject: [PATCH] Prevent stale operations by reloading them after history changes --- modules/modes/select.js | 43 ++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/modules/modes/select.js b/modules/modes/select.js index 541c65cc7..e68906bf3 100644 --- a/modules/modes/select.js +++ b/modules/modes/select.js @@ -229,13 +229,17 @@ export function modeSelect(context, selectedIDs) { return mode; }; + var operations = []; - mode.enter = function() { - if (!checkSelectedIDs()) return; + function loadOperations() { - context.features().forceVisible(selectedIDs); + operations.forEach(function(operation) { + if (operation.behavior) { + context.uninstall(operation.behavior); + } + }); - var operations = Object.values(Operations) + operations = Object.values(Operations) .map(function(o) { return o(selectedIDs, context); }) .filter(function(o) { return o.available() && o.id !== 'delete' && o.id !== 'downgrade'; }); @@ -254,10 +258,25 @@ export function modeSelect(context, selectedIDs) { operations.forEach(function(operation) { if (operation.behavior) { - behaviors.push(operation.behavior); + context.install(operation.behavior); } }); + // deprecation warning - Radial Menu to be removed in iD v3 + editMenu = isRadialMenu + ? uiRadialMenu(context, operations) + : uiEditMenu(context, operations); + + } + + + mode.enter = function() { + if (!checkSelectedIDs()) return; + + context.features().forceVisible(selectedIDs); + + loadOperations(); + behaviors.forEach(context.install); keybinding @@ -273,16 +292,11 @@ export function modeSelect(context, selectedIDs) { d3_select(document) .call(keybinding); - - // deprecation warning - Radial Menu to be removed in iD v3 - editMenu = isRadialMenu - ? uiRadialMenu(context, operations) - : uiEditMenu(context, operations); - context.ui().sidebar .select(singular() ? singular().id : null, _newFeature); context.history() + .on('change.select', loadOperations) .on('undone.select', update) .on('redone.select', update); @@ -519,6 +533,12 @@ export function modeSelect(context, selectedIDs) { if (_timeout) window.clearTimeout(_timeout); if (inspector) wrap.call(inspector.close); + operations.forEach(function(operation) { + if (operation.behavior) { + context.uninstall(operation.behavior); + } + }); + behaviors.forEach(context.uninstall); d3_select(document) @@ -528,6 +548,7 @@ export function modeSelect(context, selectedIDs) { editMenu = undefined; context.history() + .on('change.select', null) .on('undone.select', null) .on('redone.select', null);