Skip to content

Commit b88c19f

Browse files
committed
Gets rid of "config.editor.useInjectedText" in ghost text widget, as injected text is now considered stable.
1 parent ce2764c commit b88c19f

File tree

1 file changed

+4
-110
lines changed

1 file changed

+4
-110
lines changed

src/vs/editor/contrib/inlineCompletions/ghostTextWidget.ts

Lines changed: 4 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,16 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as dom from 'vs/base/browser/dom';
7-
import { Color, RGBA } from 'vs/base/common/color';
87
import { Disposable, DisposableStore, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
98
import * as strings from 'vs/base/common/strings';
109
import 'vs/css!./ghostText';
1110
import { Configuration } from 'vs/editor/browser/config/configuration';
1211
import { ContentWidgetPositionPreference, ICodeEditor, IContentWidget, IContentWidgetPosition } from 'vs/editor/browser/editorBrowser';
13-
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
1412
import { EditorFontLigatures, EditorOption, IComputedEditorOptions } from 'vs/editor/common/config/editorOptions';
15-
import { CursorColumns } from 'vs/editor/common/controller/cursorCommon';
1613
import { LineTokens } from 'vs/editor/common/core/lineTokens';
1714
import { Position } from 'vs/editor/common/core/position';
1815
import { Range } from 'vs/editor/common/core/range';
1916
import { createStringBuilder } from 'vs/editor/common/core/stringBuilder';
20-
import { IDecorationRenderOptions } from 'vs/editor/common/editorCommon';
2117
import { IModelDeltaDecoration } from 'vs/editor/common/model';
2218
import { ILanguageIdCodec } from 'vs/editor/common/modes';
2319
import { IModeService } from 'vs/editor/common/services/modeService';
@@ -26,9 +22,8 @@ import { LineDecoration } from 'vs/editor/common/viewLayout/lineDecorations';
2622
import { RenderLineInput, renderViewLine } from 'vs/editor/common/viewLayout/viewLineRenderer';
2723
import { InlineDecorationType } from 'vs/editor/common/viewModel/viewModel';
2824
import { GhostTextWidgetModel } from 'vs/editor/contrib/inlineCompletions/ghostText';
29-
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
3025
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';
3227

3328
const ttPolicy = window.trustedTypes?.createPolicy('editorGhostText', { createHTML: value => value });
3429

@@ -204,10 +199,7 @@ class DecorationsWidget implements IDisposable {
204199
private disposableStore: DisposableStore = new DisposableStore();
205200

206201
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
211203
) {
212204
}
213205

@@ -224,33 +216,11 @@ class DecorationsWidget implements IDisposable {
224216
public setParts(lineNumber: number, parts: InsertedInlineText[], hiddenText?: HiddenText): void {
225217
this.disposableStore.clear();
226218

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-
243219
const textModel = this.editor.getModel();
244220
if (!textModel) {
245221
return;
246222
}
247223

248-
const { tabSize } = textModel.getOptions();
249-
250-
const line = textModel.getLineContent(lineNumber) || '';
251-
let lastIndex = 0;
252-
let currentLinePrefix = '';
253-
254224
const hiddenTextDecorations = new Array<IModelDeltaDecoration>();
255225
if (hiddenText) {
256226
hiddenTextDecorations.push({
@@ -262,78 +232,17 @@ class DecorationsWidget implements IDisposable {
262232
});
263233
}
264234

265-
const key = this.contextKeyService.getContextKeyValue('config.editor.useInjectedText');
266-
const shouldUseInjectedText = key === undefined ? true : !!key;
267-
268235
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-
286236
return ({
287237
range: Range.fromPositions(new Position(lineNumber, p.column)),
288-
options: shouldUseInjectedText ? {
238+
options: {
289239
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' },
291241
showIfCollapsed: true,
292-
} : {
293-
...decorationType.resolve()
294242
}
295243
});
296244
}).concat(hiddenTextDecorations));
297245
}
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));
337246
}
338247

339248
class AdditionalLinesWidget implements IDisposable {
@@ -449,21 +358,6 @@ function renderLines(domNode: HTMLElement, tabSize: number, lines: LineData[], o
449358
domNode.innerHTML = trustedhtml as string;
450359
}
451360

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-
467361
class ViewMoreLinesContentWidget extends Disposable implements IContentWidget {
468362
readonly allowEditorOverflow = false;
469363
readonly suppressMouseDown = false;

0 commit comments

Comments
 (0)