From 83d2656bbc604758657a40ceebe6bef4c7fa3ff1 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Wed, 4 Mar 2020 13:10:15 -0800 Subject: [PATCH] Fix responsiveness issue when selecting features on iPad Implement an alternative solution for #6028 that doesn't rely on timeouts --- modules/behavior/select.js | 11 ++--------- modules/ui/entity_editor.js | 7 ++++--- modules/ui/sections/preset_fields.js | 2 +- modules/ui/sections/raw_tag_editor.js | 7 ++++++- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/modules/behavior/select.js b/modules/behavior/select.js index cca1ca614..a9676def7 100644 --- a/modules/behavior/select.js +++ b/modules/behavior/select.js @@ -109,17 +109,10 @@ export function behaviorSelect(context) { _p1 = null; if (dist > tolerance) return; - // Defer processing the click, - // because this click may trigger a blur event, - // and the blur event may trigger a tag change, - // and we really want that tag change to go to the already selected entity - // and not the one that we are about to select with the click #6028, #5878 - // (Be very careful entering modeSelect anywhere that might also blur a field!) var datum = d3_event.target.__data__ || (_lastMouse && _lastMouse.target.__data__); var isMultiselect = d3_event.shiftKey || d3_select('#surface .lasso').node(); - window.setTimeout(function() { - processClick(datum, isMultiselect); - }, 20); // delay > whatever raw_tag_editor.js `scheduleChange` does (10ms). + + processClick(datum, isMultiselect); } diff --git a/modules/ui/entity_editor.js b/modules/ui/entity_editor.js index ed09f7cf3..210451670 100644 --- a/modules/ui/entity_editor.js +++ b/modules/ui/entity_editor.js @@ -166,11 +166,12 @@ export function uiEntityEditor(context) { // Tag changes that fire on input can all get coalesced into a single // history operation when the user leaves the field. #2342 - function changeTags(changed, onInput) { + // Use explicit entityIDs in case the selection changes before the event is fired. + function changeTags(entityIDs, changed, onInput) { var actions = []; - for (var i in _entityIDs) { - var entityID = _entityIDs[i]; + for (var i in entityIDs) { + var entityID = entityIDs[i]; var entity = context.entity(entityID); var tags = Object.assign({}, entity.tags); // shallow copy diff --git a/modules/ui/sections/preset_fields.js b/modules/ui/sections/preset_fields.js index 64401b063..5db0f17dc 100644 --- a/modules/ui/sections/preset_fields.js +++ b/modules/ui/sections/preset_fields.js @@ -100,7 +100,7 @@ export function uiSectionPresetFields(context) { _fieldsArr.forEach(function(field) { field .on('change', function(t, onInput) { - dispatch.call('change', field, t, onInput); + dispatch.call('change', field, _entityIDs, t, onInput); }) .on('revert', function(keys) { dispatch.call('revert', field, keys); diff --git a/modules/ui/sections/raw_tag_editor.js b/modules/ui/sections/raw_tag_editor.js index d9c55c5ac..c01f659c3 100644 --- a/modules/ui/sections/raw_tag_editor.js +++ b/modules/ui/sections/raw_tag_editor.js @@ -553,9 +553,14 @@ export function uiSectionRawTagEditor(id, context) { } function scheduleChange() { + // Cache IDs in case the editor is reloaded before the change event is called. - #6028 + var entityIDs = _entityIDs; + // Delay change in case this change is blurring an edited combo. - #5878 window.setTimeout(function() { - dispatch.call('change', this, _pendingChange); + if (!_pendingChange) return; + + dispatch.call('change', this, entityIDs, _pendingChange); _pendingChange = null; }, 10); }