From 7e62751e4e04dfb895e812ecc46a8dfb9c9beb99 Mon Sep 17 00:00:00 2001 From: rr- Date: Tue, 5 Jul 2016 23:53:49 +0200 Subject: [PATCH] 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. --- client/js/controls/auto_complete_control.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/js/controls/auto_complete_control.js b/client/js/controls/auto_complete_control.js index 4a0da00c..2ee735c4 100644 --- a/client/js/controls/auto_complete_control.js +++ b/client/js/controls/auto_complete_control.js @@ -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(); });