@@ -363,13 +363,14 @@ export class InlineEditsView extends Disposable {
363
363
if (
364
364
isSingleInnerEdit
365
365
&& this . _useCodeShifting . read ( reader ) !== 'never'
366
+ && isSingleLineInsertion ( diff )
366
367
) {
367
368
if ( isSingleLineInsertionAfterPosition ( diff , inlineEdit . cursorPosition ) ) {
368
369
return 'insertionInline' ;
369
370
}
370
371
371
372
// 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.
373
374
return 'lineReplacement' ;
374
375
}
375
376
@@ -486,22 +487,35 @@ export class InlineEditsView extends Disposable {
486
487
}
487
488
}
488
489
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
+
489
505
function isSingleLineInsertionAfterPosition ( diff : DetailedLineRangeMapping [ ] , position : Position | null ) {
490
506
if ( ! position ) {
491
507
return false ;
492
508
}
509
+
510
+ if ( ! isSingleLineInsertion ( diff ) ) {
511
+ return false ;
512
+ }
513
+
493
514
const pos = position ;
494
515
495
516
return diff . every ( m => m . innerChanges ! . every ( r => isStableWordInsertion ( r ) ) ) ;
496
517
497
518
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
- }
505
519
const insertPosition = r . originalRange . getStartPosition ( ) ;
506
520
if ( pos . isBeforeOrEqual ( insertPosition ) ) {
507
521
return true ;
0 commit comments