From: David Lynch Date: Tue, 10 Nov 2015 23:59:27 +0000 (-0800) Subject: TitleSearchWidget: Only update results if the query is current X-Git-Tag: 1.31.0-rc.0~9019^2 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=4b3ecbcbc93887658768616962af5d427915ccdd;p=lhc%2Fweb%2Fwiklou.git 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 --- 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; } ); };