@@ -12,6 +12,7 @@ import { LineSource, renderLines, RenderOptions } from '../../../../../browser/w
12
12
import { diffAddDecoration } from '../../../../../browser/widget/diffEditor/registrations.contribution.js' ;
13
13
import { applyViewZones , IObservableViewZone } from '../../../../../browser/widget/diffEditor/utils.js' ;
14
14
import { EditorOption } from '../../../../../common/config/editorOptions.js' ;
15
+ import { OffsetRange } from '../../../../../common/core/offsetRange.js' ;
15
16
import { Range } from '../../../../../common/core/range.js' ;
16
17
import { AbstractText } from '../../../../../common/core/textEdit.js' ;
17
18
import { DetailedLineRangeMapping } from '../../../../../common/diff/rangeMapping.js' ;
@@ -36,6 +37,8 @@ export class OriginalEditorInlineDiffView extends Disposable implements IInlineE
36
37
37
38
readonly isHovered = constObservable ( false ) ;
38
39
40
+ private readonly _tokenizationFinished = modelTokenizationFinished ( this . _modifiedTextModel ) ;
41
+
39
42
constructor (
40
43
private readonly _originalEditor : ICodeEditor ,
41
44
private readonly _state : IObservable < IOriginalEditorInlineDiffViewState | undefined > ,
@@ -55,8 +58,6 @@ export class OriginalEditorInlineDiffView extends Disposable implements IInlineE
55
58
56
59
const editor = observableCodeEditor ( this . _originalEditor ) ;
57
60
58
- const tokenizationFinished = modelTokenizationFinished ( _modifiedTextModel ) ;
59
-
60
61
const originalViewZones = derived ( this , ( reader ) => {
61
62
const originalModel = editor . model . read ( reader ) ;
62
63
if ( ! originalModel ) { return [ ] ; }
@@ -73,7 +74,7 @@ export class OriginalEditorInlineDiffView extends Disposable implements IInlineE
73
74
continue ;
74
75
}
75
76
76
- tokenizationFinished . read ( reader ) ; // Update view-zones once tokenization completes
77
+ this . _tokenizationFinished . read ( reader ) ; // Update view-zones once tokenization completes
77
78
78
79
const source = new LineSource ( diff . modified . mapToLineArray ( l => this . _modifiedTextModel . tokenization . getLineTokens ( l ) ) ) ;
79
80
@@ -217,15 +218,26 @@ export class OriginalEditorInlineDiffView extends Disposable implements IInlineE
217
218
// when the injected text becomes long, the editor will split it into multiple spans
218
219
// to be able to get the border around the start and end of the text, we need to split it into multiple segments
219
220
const textSegments = insertedText . length > 3 ?
220
- [ { text : insertedText . slice ( 0 , 1 ) , extraClasses : [ 'start' ] } , { text : insertedText . slice ( 1 , - 1 ) , extraClasses : [ ] } , { text : insertedText . slice ( - 1 ) , extraClasses : [ 'end' ] } ] :
221
- [ { text : insertedText , extraClasses : [ 'start' , 'end' ] } ] ;
222
-
223
- for ( const { text, extraClasses } of textSegments ) {
221
+ [
222
+ { text : insertedText . slice ( 0 , 1 ) , extraClasses : [ 'start' ] , offsetRange : new OffsetRange ( i . modifiedRange . startColumn - 1 , i . modifiedRange . startColumn ) } ,
223
+ { text : insertedText . slice ( 1 , - 1 ) , extraClasses : [ ] , offsetRange : new OffsetRange ( i . modifiedRange . startColumn , i . modifiedRange . endColumn - 2 ) } ,
224
+ { text : insertedText . slice ( - 1 ) , extraClasses : [ 'end' ] , offsetRange : new OffsetRange ( i . modifiedRange . endColumn - 2 , i . modifiedRange . endColumn - 1 ) }
225
+ ] :
226
+ [
227
+ { text : insertedText , extraClasses : [ 'start' , 'end' ] , offsetRange : new OffsetRange ( i . modifiedRange . startColumn - 1 , i . modifiedRange . endColumn ) }
228
+ ] ;
229
+
230
+ // Tokenization
231
+ this . _tokenizationFinished . read ( reader ) ; // reconsider when tokenization is finished
232
+ const lineTokens = this . _modifiedTextModel . tokenization . getLineTokens ( i . modifiedRange . startLineNumber ) ;
233
+
234
+ for ( const { text, extraClasses, offsetRange } of textSegments ) {
224
235
originalDecorations . push ( {
225
236
range : Range . fromPositions ( i . originalRange . getEndPosition ( ) ) ,
226
237
options : {
227
238
description : 'inserted-text' ,
228
239
before : {
240
+ tokens : lineTokens . getTokensInRange ( offsetRange ) ,
229
241
content : text ,
230
242
inlineClassName : classNames (
231
243
'inlineCompletions-char-insert' ,
0 commit comments