Skip to content

Commit e934023

Browse files
authored
Merge pull request microsoft#211284 from microsoft/tyriar/211192
Complete left side of completion if it differs
2 parents 73f7941 + 75ff82d commit e934023

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/vs/workbench/contrib/terminalContrib/suggest/browser/terminalSuggestAddon.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,19 +425,30 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
425425
const currentPromptInputState = this._currentPromptInputState ?? initialPromptInputState;
426426
const additionalInput = currentPromptInputState.value.substring(initialPromptInputState.cursorIndex, currentPromptInputState.cursorIndex);
427427

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
429429
const initialInput = initialPromptInputState.value.substring(0, initialPromptInputState.cursorIndex);
430430
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+
}
432439

433440
// Send the completion
434441
this._onAcceptedCompletion.fire([
435442
// Disable suggestions
436443
'\x1b[24~y',
437444
// Backspace to remove all additional input
438445
'\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,
439450
// Write the completion
440-
finalCompletion,
451+
finalCompletionRightSide,
441452
// Enable suggestions
442453
'\x1b[24~z',
443454
].join(''));

0 commit comments

Comments
 (0)