@@ -425,19 +425,30 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
425
425
const currentPromptInputState = this . _currentPromptInputState ?? initialPromptInputState ;
426
426
const additionalInput = currentPromptInputState . value . substring ( initialPromptInputState . cursorIndex , currentPromptInputState . cursorIndex ) ;
427
427
428
- // We could start from a common prefix to reduce the number of characters we need to send
428
+ // Get the final completion on the right side of the cursor
429
429
const initialInput = initialPromptInputState . value . substring ( 0 , initialPromptInputState . cursorIndex ) ;
430
430
const lastSpaceIndex = initialInput . lastIndexOf ( ' ' ) ;
431
- const finalCompletion = suggestion . item . completion . label . substring ( initialPromptInputState . cursorIndex - ( lastSpaceIndex === - 1 ? 0 : lastSpaceIndex + 1 ) ) ;
431
+ const finalCompletionRightSide = suggestion . item . completion . label . substring ( initialPromptInputState . cursorIndex - ( lastSpaceIndex === - 1 ? 0 : lastSpaceIndex + 1 ) ) ;
432
+
433
+ // Get the final completion on the right side of the cursor if it differs from the initial
434
+ // propmt input state
435
+ let finalCompletionLeftSide = suggestion . item . completion . label . substring ( 0 , initialPromptInputState . cursorIndex - ( lastSpaceIndex === - 1 ? 0 : lastSpaceIndex + 1 ) ) ;
436
+ if ( initialInput . endsWith ( finalCompletionLeftSide ) ) {
437
+ finalCompletionLeftSide = '' ;
438
+ }
432
439
433
440
// Send the completion
434
441
this . _onAcceptedCompletion . fire ( [
435
442
// Disable suggestions
436
443
'\x1b[24~y' ,
437
444
// Backspace to remove all additional input
438
445
'\x7F' . repeat ( additionalInput . length ) ,
446
+ // Backspace to remove left side of completion
447
+ '\x7F' . repeat ( finalCompletionLeftSide . length ) ,
448
+ // Write the left side of the completion if it differed
449
+ finalCompletionLeftSide ,
439
450
// Write the completion
440
- finalCompletion ,
451
+ finalCompletionRightSide ,
441
452
// Enable suggestions
442
453
'\x1b[24~z' ,
443
454
] . join ( '' ) ) ;
0 commit comments