From dabbd89e5d2b1d7cb7c55a6a13086e249e310893 Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Wed, 8 Nov 2023 10:42:09 +0100 Subject: [PATCH] suppress autocomplete for taginfo results if field has static values fixes #9898 Fixes a problem that occurs because the order of the field `options` can be in general different from the order returned by taginfo (taginfo sorts by usage, while presets typically are sorted alphabetically), causing different values to be potentially selected for autocomplete values. As the taginfo results typically come in a few moments delayed, this can lead to confusing behaviour. This solves it by just not reattempting an autocomplete using the taginfo results, if a field has static options available. --- modules/ui/combobox.js | 8 ++++---- modules/ui/fields/combo.js | 11 +++++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/modules/ui/combobox.js b/modules/ui/combobox.js index 057787aa5..3914fd186 100644 --- a/modules/ui/combobox.js +++ b/modules/ui/combobox.js @@ -230,12 +230,12 @@ export function uiCombobox(context, klass) { // Called whenever the input value is changed (e.g. on typing) function change(doAutoComplete) { if (doAutoComplete === undefined) doAutoComplete = true; - fetchComboData(value(), function() { + fetchComboData(value(), function(skipAutosuggest) { _selected = null; var val = input.property('value'); if (_suggestions.length) { - if (doAutoComplete && input.property('selectionEnd') === val.length) { + if (doAutoComplete && !skipAutosuggest && input.property('selectionEnd') === val.length) { _selected = tryAutocomplete(); } @@ -319,7 +319,7 @@ export function uiCombobox(context, klass) { function fetchComboData(v, cb) { _cancelFetch = false; - _fetcher.call(input, v, function(results) { + _fetcher.call(input, v, function(results, skipAutosuggest) { // already chose a value, don't overwrite or autocomplete it if (_cancelFetch) return; @@ -327,7 +327,7 @@ export function uiCombobox(context, klass) { results.forEach(function(d) { _fetched[d.value] = d; }); if (cb) { - cb(); + cb(skipAutosuggest); } }); } diff --git a/modules/ui/fields/combo.js b/modules/ui/fields/combo.js index 4aaa05b50..1a224d7cd 100644 --- a/modules/ui/fields/combo.js +++ b/modules/ui/fields/combo.js @@ -194,6 +194,11 @@ export function uiFieldCombo(field, context) { } + function hasStaticValues() { + return getOptions().length > 0; + } + + function setStaticValues(callback, filter) { _comboData = getOptions(); @@ -209,7 +214,9 @@ export function uiFieldCombo(field, context) { function setTaginfoValues(q, callback) { var queryFilter = d => d.value.toLowerCase().includes(q.toLowerCase()) || d.key.toLowerCase().includes(q.toLowerCase()); - setStaticValues(callback, queryFilter); + if (hasStaticValues()) { + setStaticValues(callback, queryFilter); + } var stringsField = field.resolveReference('stringsCrossReference'); var fn = _isMulti ? 'multikeys' : 'values'; @@ -283,7 +290,7 @@ export function uiFieldCombo(field, context) { _comboData = _comboData.filter(queryFilter); _comboData = objectDifference(_comboData, _multiData); - if (callback) callback(_comboData); + if (callback) callback(_comboData, hasStaticValues()); }); }