From 4b3ecbcbc93887658768616962af5d427915ccdd Mon Sep 17 00:00:00 2001 From: David Lynch Date: Tue, 10 Nov 2015 15:59:27 -0800 Subject: [PATCH] TitleSearchWidget: Only update results if the query is current With near-simultaneous inputs (e.g. holding down the backspace key while deleting text) you can cause the suggestion promise to resolve out-of-order. This causes apparently incorrect suggestions to be displayed for the current input. To fix this, abort the existing promise if it exists. Bug: T114178 Change-Id: I9332452fd914b54e7c564284da2a8a00865ae806 --- .../mediawiki.widgets/mw.widgets.TitleSearchWidget.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/resources/src/mediawiki.widgets/mw.widgets.TitleSearchWidget.js b/resources/src/mediawiki.widgets/mw.widgets.TitleSearchWidget.js index 0e2546f8b7..546fbf8f87 100644 --- a/resources/src/mediawiki.widgets/mw.widgets.TitleSearchWidget.js +++ b/resources/src/mediawiki.widgets/mw.widgets.TitleSearchWidget.js @@ -72,11 +72,18 @@ mw.widgets.TitleSearchWidget.prototype.onQueryChange = function () { var widget = this; - this.getSuggestionsPromise().done( function ( response ) { + if ( this.currentRequest ) { + this.currentRequest.abort(); + } + + this.currentRequest = this.getSuggestionsPromise(); + this.currentRequest.done( function ( response ) { // Parent method mw.widgets.TitleSearchWidget.parent.prototype.onQueryChange.call( widget ); widget.results.addItems( widget.getOptionsFromData( response.query || {} ) ); + + widget.currentRequest = false; } ); }; -- 2.20.1