@@ -91,16 +91,17 @@ class Autocomplete {
91
91
var initialPosition = this . completionProvider && this . completionProvider . initialPosition ;
92
92
if ( this . autoShown || ( this . popup && this . popup . isOpen ) || ! initialPosition ) return ;
93
93
94
- var completionsForEmpty = [ {
95
- caption : config . nls ( "Loading..." ) ,
96
- value : ""
97
- } ] ;
98
- this . completions = new FilteredList ( completionsForEmpty ) ;
94
+ this . completions = new FilteredList ( Autocomplete . completionsForLoading ) ;
99
95
this . openPopup ( this . editor , initialPosition . prefix , false ) ;
100
96
this . popup . renderer . setStyle ( "ace_loading" , true ) ;
101
97
} . bind ( this ) , this . stickySelectionDelay ) ;
102
98
}
103
99
100
+ static completionsForLoading = [ {
101
+ caption : config . nls ( "Loading..." ) ,
102
+ value : ""
103
+ } ] ;
104
+
104
105
$init ( ) {
105
106
this . popup = new AcePopup ( this . parentNode || document . body || document . documentElement ) ;
106
107
this . popup . on ( "click" , function ( e ) {
@@ -238,7 +239,8 @@ class Autocomplete {
238
239
this . popup . autoSelect = this . autoSelect ;
239
240
this . popup . setSelectOnHover ( this . setSelectOnHover ) ;
240
241
241
- var previousSelectedItem = this . popup . data [ this . popup . getRow ( ) ] ;
242
+ var oldRow = this . popup . getRow ( ) ;
243
+ var previousSelectedItem = this . popup . data [ oldRow ] ;
242
244
243
245
this . popup . setData ( this . completions . filtered , this . completions . filterText ) ;
244
246
if ( this . editor . textInput . setAriaOptions ) {
@@ -250,12 +252,17 @@ class Autocomplete {
250
252
251
253
editor . keyBinding . addKeyboardHandler ( this . keyboardHandler ) ;
252
254
253
- var newRow = this . popup . data . indexOf ( previousSelectedItem ) ;
254
-
255
- if ( newRow && this . stickySelection )
256
- this . popup . setRow ( this . autoSelect ? newRow : - 1 ) ;
257
- else
258
- this . popup . setRow ( this . autoSelect ? 0 : - 1 ) ;
255
+ var newRow ;
256
+ if ( this . stickySelection )
257
+ newRow = this . popup . data . indexOf ( previousSelectedItem ) ;
258
+ if ( ! newRow || newRow === - 1 )
259
+ newRow = 0 ;
260
+
261
+ this . popup . setRow ( this . autoSelect ? newRow : - 1 ) ;
262
+
263
+ // If we stay on the same row, but the content is different, we want to update the popup.
264
+ if ( newRow === oldRow && previousSelectedItem !== this . completions . filtered [ newRow ] )
265
+ this . $onPopupChange ( ) ;
259
266
260
267
if ( ! keepPopupPosition ) {
261
268
this . popup . setTheme ( editor . getTheme ( ) ) ;
@@ -458,6 +465,7 @@ class Autocomplete {
458
465
} ] ;
459
466
this . completions = new FilteredList ( completionsForEmpty ) ;
460
467
this . openPopup ( this . editor , prefix , keepPopupPosition ) ;
468
+ this . popup . renderer . setStyle ( "ace_loading" , false ) ;
461
469
return ;
462
470
}
463
471
return this . detach ( ) ;
@@ -471,7 +479,12 @@ class Autocomplete {
471
479
if ( this . autoInsert && ! this . autoShown && filtered . length == 1 )
472
480
return this . insertMatch ( filtered [ 0 ] ) ;
473
481
}
474
- this . completions = completions ;
482
+ this . completions = finished ?
483
+ completions :
484
+ new FilteredList (
485
+ Autocomplete . completionsForLoading . concat ( filtered ) , completions . filterText
486
+ ) ;
487
+
475
488
this . openPopup ( this . editor , prefix , keepPopupPosition ) ;
476
489
477
490
this . popup . renderer . setStyle ( "ace_loading" , ! finished ) ;
0 commit comments