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.
This commit is contained in:
Martin Raifer
2023-11-08 10:42:09 +01:00
parent c4d1390270
commit dabbd89e5d
2 changed files with 13 additions and 6 deletions

View File

@@ -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);
}
});
}

View File

@@ -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());
});
}