Skip to content

Commit b16f9b1

Browse files
authored
Improve line replacement logic for single line insertions (microsoft#250297)
lineReplacement picked to often
1 parent 8e9b67d commit b16f9b1

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/vs/editor/contrib/inlineCompletions/browser/view/inlineEdits/inlineEditsView.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,14 @@ export class InlineEditsView extends Disposable {
363363
if (
364364
isSingleInnerEdit
365365
&& this._useCodeShifting.read(reader) !== 'never'
366+
&& isSingleLineInsertion(diff)
366367
) {
367368
if (isSingleLineInsertionAfterPosition(diff, inlineEdit.cursorPosition)) {
368369
return 'insertionInline';
369370
}
370371

371372
// If we have a single line insertion before the cursor position, we do not want to move the cursor by inserting
372-
// the suggestion inline. Use a line replacement view instead
373+
// the suggestion inline. Use a line replacement view instead. Do not use word replacement view.
373374
return 'lineReplacement';
374375
}
375376

@@ -486,22 +487,35 @@ export class InlineEditsView extends Disposable {
486487
}
487488
}
488489

490+
function isSingleLineInsertion(diff: DetailedLineRangeMapping[]) {
491+
return diff.every(m => m.innerChanges!.every(r => isWordInsertion(r)));
492+
493+
function isWordInsertion(r: RangeMapping) {
494+
if (!r.originalRange.isEmpty()) {
495+
return false;
496+
}
497+
const isInsertionWithinLine = r.modifiedRange.startLineNumber === r.modifiedRange.endLineNumber;
498+
if (!isInsertionWithinLine) {
499+
return false;
500+
}
501+
return true;
502+
}
503+
}
504+
489505
function isSingleLineInsertionAfterPosition(diff: DetailedLineRangeMapping[], position: Position | null) {
490506
if (!position) {
491507
return false;
492508
}
509+
510+
if (!isSingleLineInsertion(diff)) {
511+
return false;
512+
}
513+
493514
const pos = position;
494515

495516
return diff.every(m => m.innerChanges!.every(r => isStableWordInsertion(r)));
496517

497518
function isStableWordInsertion(r: RangeMapping) {
498-
if (!r.originalRange.isEmpty()) {
499-
return false;
500-
}
501-
const isInsertionWithinLine = r.modifiedRange.startLineNumber === r.modifiedRange.endLineNumber;
502-
if (!isInsertionWithinLine) {
503-
return false;
504-
}
505519
const insertPosition = r.originalRange.getStartPosition();
506520
if (pos.isBeforeOrEqual(insertPosition)) {
507521
return true;

0 commit comments

Comments
 (0)