@@ -274,18 +274,33 @@ public void documentChanged(final DocumentEvent event) {
274
274
}
275
275
String currentSuggestion = session .getCurrentSuggestion ().getInsertText ();
276
276
int currentOffset = widget .getCaretOffset ();
277
+
277
278
if (input .isEmpty ()) {
278
279
if (distanceTraversed <= 0 ) {
280
+ // discard all suggestions as caret position is less than request invocation position
281
+ session .updateCompletionStates (new ArrayList <String >());
279
282
session .transitionToDecisionMade ();
280
283
session .end ();
281
284
return ;
282
285
}
283
286
distanceTraversed = typeaheadProcessor .getNewDistanceTraversedOnDeleteAndUpdateBracketState (
284
287
event .getLength (), distanceTraversed , brackets );
285
288
if (distanceTraversed < 0 ) {
289
+ // discard all suggestions as caret position is less than request invocation position
290
+ session .updateCompletionStates (new ArrayList <String >());
286
291
session .transitionToDecisionMade ();
287
292
session .end ();
288
293
}
294
+
295
+ // note: distanceTraversed as 0 is currently understood to be when a user presses BS removing any typeahead
296
+ if (distanceTraversed == 0 ) {
297
+ // reset completion states for all suggestions when user reverts to request
298
+ // invocation state
299
+ session .resetCompletionStates ();
300
+ // mark currently displayed suggestion as seen
301
+ session .markSuggestionAsSeen ();
302
+ }
303
+
289
304
return ;
290
305
}
291
306
@@ -328,12 +343,19 @@ public void documentChanged(final DocumentEvent event) {
328
343
session .transitionToDecisionMade (lineToUnsetIndent );
329
344
Display .getCurrent ().asyncExec (() -> {
330
345
if (session .isActive ()) {
331
- session .end ();
346
+ // discard suggestions and end immediately as typeahead does not match
347
+ session .updateCompletionStates (new ArrayList <String >());
348
+ session .endImmediately ();
332
349
}
333
350
});
334
351
return ;
335
352
}
336
353
354
+ // discard all other suggestions except for current one as typeahead matches it
355
+ // also mark current one as seen as it continues to be displayed
356
+ session .updateCompletionStates (List .of (session .getCurrentSuggestion ().getItemId ()));
357
+ session .markSuggestionAsSeen ();
358
+
337
359
// Here we perform "post closing bracket insertion caret correction", which
338
360
// consists of the following:
339
361
// - Check if the input is a closing bracket
@@ -398,7 +420,7 @@ public void mouseDown(final MouseEvent e) {
398
420
int currentOffset = invocationOffset + distanceTraversed ;
399
421
int lastKnownLine = widget .getLineAtOffset (currentOffset );
400
422
qInvocationSessionInstance .transitionToDecisionMade (lastKnownLine + 1 );
401
- qInvocationSessionInstance .end ();
423
+ qInvocationSessionInstance .endImmediately ();
402
424
return ;
403
425
}
404
426
0 commit comments