4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
6
import * as dom from 'vs/base/browser/dom' ;
7
- import { Color , RGBA } from 'vs/base/common/color' ;
8
7
import { Disposable , DisposableStore , IDisposable , toDisposable } from 'vs/base/common/lifecycle' ;
9
8
import * as strings from 'vs/base/common/strings' ;
10
9
import 'vs/css!./ghostText' ;
11
10
import { Configuration } from 'vs/editor/browser/config/configuration' ;
12
11
import { ContentWidgetPositionPreference , ICodeEditor , IContentWidget , IContentWidgetPosition } from 'vs/editor/browser/editorBrowser' ;
13
- import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService' ;
14
12
import { EditorFontLigatures , EditorOption , IComputedEditorOptions } from 'vs/editor/common/config/editorOptions' ;
15
- import { CursorColumns } from 'vs/editor/common/controller/cursorCommon' ;
16
13
import { LineTokens } from 'vs/editor/common/core/lineTokens' ;
17
14
import { Position } from 'vs/editor/common/core/position' ;
18
15
import { Range } from 'vs/editor/common/core/range' ;
19
16
import { createStringBuilder } from 'vs/editor/common/core/stringBuilder' ;
20
- import { IDecorationRenderOptions } from 'vs/editor/common/editorCommon' ;
21
17
import { IModelDeltaDecoration } from 'vs/editor/common/model' ;
22
18
import { ILanguageIdCodec } from 'vs/editor/common/modes' ;
23
19
import { IModeService } from 'vs/editor/common/services/modeService' ;
@@ -26,9 +22,8 @@ import { LineDecoration } from 'vs/editor/common/viewLayout/lineDecorations';
26
22
import { RenderLineInput , renderViewLine } from 'vs/editor/common/viewLayout/viewLineRenderer' ;
27
23
import { InlineDecorationType } from 'vs/editor/common/viewModel/viewModel' ;
28
24
import { GhostTextWidgetModel } from 'vs/editor/contrib/inlineCompletions/ghostText' ;
29
- import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
30
25
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
31
- import { IThemeService , registerThemingParticipant } from 'vs/platform/theme/common/themeService' ;
26
+ import { registerThemingParticipant } from 'vs/platform/theme/common/themeService' ;
32
27
33
28
const ttPolicy = window . trustedTypes ?. createPolicy ( 'editorGhostText' , { createHTML : value => value } ) ;
34
29
@@ -204,10 +199,7 @@ class DecorationsWidget implements IDisposable {
204
199
private disposableStore : DisposableStore = new DisposableStore ( ) ;
205
200
206
201
constructor (
207
- private readonly editor : ICodeEditor ,
208
- @ICodeEditorService private readonly codeEditorService : ICodeEditorService ,
209
- @IThemeService private readonly themeService : IThemeService ,
210
- @IContextKeyService private readonly contextKeyService : IContextKeyService
202
+ private readonly editor : ICodeEditor
211
203
) {
212
204
}
213
205
@@ -224,33 +216,11 @@ class DecorationsWidget implements IDisposable {
224
216
public setParts ( lineNumber : number , parts : InsertedInlineText [ ] , hiddenText ?: HiddenText ) : void {
225
217
this . disposableStore . clear ( ) ;
226
218
227
- const colorTheme = this . themeService . getColorTheme ( ) ;
228
- const foreground = colorTheme . getColor ( ghostTextForeground ) ;
229
-
230
- let opacity : string | undefined = undefined ;
231
- let color : string | undefined = undefined ;
232
- if ( foreground ) {
233
- opacity = String ( foreground . rgba . a ) ;
234
- color = Color . Format . CSS . format ( opaque ( foreground ) ) ! ;
235
- }
236
-
237
- const borderColor = colorTheme . getColor ( ghostTextBorder ) ;
238
- let border : string | undefined = undefined ;
239
- if ( borderColor ) {
240
- border = `2px dashed ${ borderColor } ` ;
241
- }
242
-
243
219
const textModel = this . editor . getModel ( ) ;
244
220
if ( ! textModel ) {
245
221
return ;
246
222
}
247
223
248
- const { tabSize } = textModel . getOptions ( ) ;
249
-
250
- const line = textModel . getLineContent ( lineNumber ) || '' ;
251
- let lastIndex = 0 ;
252
- let currentLinePrefix = '' ;
253
-
254
224
const hiddenTextDecorations = new Array < IModelDeltaDecoration > ( ) ;
255
225
if ( hiddenText ) {
256
226
hiddenTextDecorations . push ( {
@@ -262,78 +232,17 @@ class DecorationsWidget implements IDisposable {
262
232
} ) ;
263
233
}
264
234
265
- const key = this . contextKeyService . getContextKeyValue ( 'config.editor.useInjectedText' ) ;
266
- const shouldUseInjectedText = key === undefined ? true : ! ! key ;
267
-
268
235
this . decorationIds = this . editor . deltaDecorations ( this . decorationIds , parts . map < IModelDeltaDecoration > ( p => {
269
- currentLinePrefix += line . substring ( lastIndex , p . column - 1 ) ;
270
- lastIndex = p . column - 1 ;
271
-
272
- // To avoid visual confusion, we don't want to render visible whitespace
273
- const contentText = shouldUseInjectedText ? p . text : this . renderSingleLineText ( p . text , currentLinePrefix , tabSize , false ) ;
274
-
275
- const decorationType = this . disposableStore . add ( registerDecorationType ( this . codeEditorService , 'ghost-text' , '0-ghost-text-' , {
276
- after : {
277
- // TODO: escape?
278
- contentText,
279
- opacity,
280
- color,
281
- border,
282
- fontWeight : p . preview ? 'bold' : 'normal' ,
283
- } ,
284
- } ) ) ;
285
-
286
236
return ( {
287
237
range : Range . fromPositions ( new Position ( lineNumber , p . column ) ) ,
288
- options : shouldUseInjectedText ? {
238
+ options : {
289
239
description : 'ghost-text' ,
290
- after : { content : contentText , inlineClassName : p . preview ? 'ghost-text-decoration-preview' : 'ghost-text-decoration' } ,
240
+ after : { content : p . text , inlineClassName : p . preview ? 'ghost-text-decoration-preview' : 'ghost-text-decoration' } ,
291
241
showIfCollapsed : true ,
292
- } : {
293
- ...decorationType . resolve ( )
294
242
}
295
243
} ) ;
296
244
} ) . concat ( hiddenTextDecorations ) ) ;
297
245
}
298
-
299
- private renderSingleLineText ( text : string , lineStart : string , tabSize : number , renderWhitespace : boolean ) : string {
300
- const newLine = lineStart + text ;
301
- const visibleColumnsByColumns = CursorColumns . visibleColumnsByColumns ( newLine , tabSize ) ;
302
-
303
- let contentText = '' ;
304
- let curCol = lineStart . length + 1 ;
305
- for ( const c of text ) {
306
- if ( c === '\t' ) {
307
- const width = visibleColumnsByColumns [ curCol + 1 ] - visibleColumnsByColumns [ curCol ] ;
308
- if ( renderWhitespace ) {
309
- contentText += '→' ;
310
- for ( let i = 1 ; i < width ; i ++ ) {
311
- contentText += '\xa0' ;
312
- }
313
- } else {
314
- for ( let i = 0 ; i < width ; i ++ ) {
315
- contentText += '\xa0' ;
316
- }
317
- }
318
- } else if ( c === ' ' ) {
319
- if ( renderWhitespace ) {
320
- contentText += '·' ;
321
- } else {
322
- contentText += '\xa0' ;
323
- }
324
- } else {
325
- contentText += c ;
326
- }
327
- curCol += 1 ;
328
- }
329
-
330
- return contentText ;
331
- }
332
- }
333
-
334
- function opaque ( color : Color ) : Color {
335
- const { r, b, g } = color . rgba ;
336
- return new Color ( new RGBA ( r , g , b , 255 ) ) ;
337
246
}
338
247
339
248
class AdditionalLinesWidget implements IDisposable {
@@ -449,21 +358,6 @@ function renderLines(domNode: HTMLElement, tabSize: number, lines: LineData[], o
449
358
domNode . innerHTML = trustedhtml as string ;
450
359
}
451
360
452
- let keyCounter = 0 ;
453
-
454
- function registerDecorationType ( service : ICodeEditorService , description : string , keyPrefix : string , options : IDecorationRenderOptions ) {
455
- const key = keyPrefix + ( keyCounter ++ ) ;
456
- service . registerDecorationType ( description , key , options ) ;
457
- return {
458
- dispose ( ) {
459
- service . removeDecorationType ( key ) ;
460
- } ,
461
- resolve ( ) {
462
- return service . resolveDecorationOptions ( key , true ) ;
463
- }
464
- } ;
465
- }
466
-
467
361
class ViewMoreLinesContentWidget extends Disposable implements IContentWidget {
468
362
readonly allowEditorOverflow = false ;
469
363
readonly suppressMouseDown = false ;
0 commit comments