client/tags: fix hovering over autocomplete in FF

Hovering over an autocomplete box always selected the last element
rather than the element under the cursor. This is because resultIndex
was bound by reference.

This looks like a bug in FF implementation of "for (let [x, y] of ...)"
-rather than binding "x" and "y" to the scope of the loop, it's
equivalent to "for (var [x, y] of ...)", which causes nasty anomalies
for functions created inside the loop body.
This commit is contained in:
rr- 2016-07-05 23:53:49 +02:00
parent 0d9c2b7cc8
commit 7e62751e4e

View file

@ -211,6 +211,7 @@ class AutoCompleteControl {
this._suggestionList.removeChild(this._suggestionList.firstChild);
}
for (let [resultIndex, resultItem] of this._results.entries()) {
let resultIndexWorkaround = resultIndex;
const listItem = document.createElement('li');
const link = document.createElement('a');
link.href = '#';
@ -220,14 +221,14 @@ class AutoCompleteControl {
'mouseenter',
e => {
e.preventDefault();
this._activeResult = resultIndex;
this._activeResult = resultIndexWorkaround;
this._refreshActiveResult();
});
link.addEventListener(
'mousedown',
e => {
e.preventDefault();
this._activeResult = resultIndex;
this._activeResult = resultIndexWorkaround;
this._options.confirm(this._getActiveSuggestion());
this.hide();
});