Skip to content

Commit 7191317

Browse files
authored
css variables all the way (microsoft#167180)
fixes microsoft#166729
1 parent 3dc0754 commit 7191317

File tree

3 files changed

+21
-30
lines changed

3 files changed

+21
-30
lines changed

src/vs/editor/contrib/codelens/browser/codelensController.ts

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import * as dom from 'vs/base/browser/dom';
6+
77
import { CancelablePromise, createCancelablePromise, disposableTimeout, RunOnceScheduler } from 'vs/base/common/async';
88
import { onUnexpectedError, onUnexpectedExternalError } from 'vs/base/common/errors';
9-
import { hash } from 'vs/base/common/hash';
109
import { DisposableStore, toDisposable } from 'vs/base/common/lifecycle';
1110
import { StableEditorScrollState } from 'vs/editor/browser/stableEditorScroll';
1211
import { IActiveCodeEditor, ICodeEditor, IViewZoneChangeAccessor, MouseTargetType } from 'vs/editor/browser/editorBrowser';
@@ -32,8 +31,7 @@ export class CodeLensContribution implements IEditorContribution {
3231

3332
private readonly _disposables = new DisposableStore();
3433
private readonly _localToDispose = new DisposableStore();
35-
private readonly _styleElement: HTMLStyleElement;
36-
private readonly _styleClassName: string;
34+
3735
private readonly _lenses: CodeLensWidget[] = [];
3836

3937
private readonly _provideCodeLensDebounce: IFeatureDebounceInformation;
@@ -70,12 +68,6 @@ export class CodeLensContribution implements IEditorContribution {
7068
this._disposables.add(_languageFeaturesService.codeLensProvider.onDidChange(this._onModelChange, this));
7169
this._onModelChange();
7270

73-
this._styleClassName = '_' + hash(this._editor.getId()).toString(16);
74-
this._styleElement = dom.createStyleSheet(
75-
dom.isInShadowDOM(this._editor.getContainerDomNode())
76-
? this._editor.getContainerDomNode()
77-
: undefined
78-
);
7971
this._updateLensStyle();
8072
}
8173

@@ -84,7 +76,6 @@ export class CodeLensContribution implements IEditorContribution {
8476
this._disposables.dispose();
8577
this._oldCodeLensModels.dispose();
8678
this._currentCodeLensModel?.dispose();
87-
this._styleElement.remove();
8879
}
8980

9081
private _getLayoutInfo() {
@@ -105,19 +96,16 @@ export class CodeLensContribution implements IEditorContribution {
10596
const fontFamily = this._editor.getOption(EditorOption.codeLensFontFamily);
10697
const editorFontInfo = this._editor.getOption(EditorOption.fontInfo);
10798

108-
const fontFamilyVar = `--codelens-font-family${this._styleClassName}`;
109-
const fontFeaturesVar = `--codelens-font-features${this._styleClassName}`;
99+
const { style } = this._editor.getContainerDomNode();
100+
101+
style.setProperty('--vscode-editorCodeLens-lineHeight', `${codeLensHeight}px`);
102+
style.setProperty('--vscode-editorCodeLens-fontSize', `${fontSize}px`);
103+
style.setProperty('--vscode-editorCodeLens-fontFeatureSettings', editorFontInfo.fontFeatureSettings);
110104

111-
let newStyle = `
112-
.monaco-editor .codelens-decoration.${this._styleClassName} { line-height: ${codeLensHeight}px; font-size: ${fontSize}px; padding-right: ${Math.round(fontSize * 0.5)}px; font-feature-settings: var(${fontFeaturesVar}) }
113-
.monaco-editor .codelens-decoration.${this._styleClassName} span.codicon { line-height: ${codeLensHeight}px; font-size: ${fontSize}px; }
114-
`;
115105
if (fontFamily) {
116-
newStyle += `.monaco-editor .codelens-decoration.${this._styleClassName} { font-family: var(${fontFamilyVar}), ${EDITOR_FONT_DEFAULTS.fontFamily}}`;
106+
style.setProperty('--vscode-editorCodeLens-fontFamily', fontFamily);
107+
style.setProperty('--vscode-editorCodeLens-fontFamilyDefault', EDITOR_FONT_DEFAULTS.fontFamily);
117108
}
118-
this._styleElement.textContent = newStyle;
119-
this._editor.getContainerDomNode().style.setProperty(fontFamilyVar, fontFamily ?? 'inherit');
120-
this._editor.getContainerDomNode().style.setProperty(fontFeaturesVar, editorFontInfo.fontFeatureSettings);
121109

122110
//
123111
this._editor.changeViewZones(accessor => {
@@ -345,7 +333,7 @@ export class CodeLensContribution implements IEditorContribution {
345333
groupsIndex++;
346334
codeLensIndex++;
347335
} else {
348-
this._lenses.splice(codeLensIndex, 0, new CodeLensWidget(groups[groupsIndex], <IActiveCodeEditor>this._editor, this._styleClassName, helper, viewZoneAccessor, layoutInfo.codeLensHeight, () => this._resolveCodeLensesInViewportSoon()));
336+
this._lenses.splice(codeLensIndex, 0, new CodeLensWidget(groups[groupsIndex], <IActiveCodeEditor>this._editor, helper, viewZoneAccessor, layoutInfo.codeLensHeight, () => this._resolveCodeLensesInViewportSoon()));
349337
codeLensIndex++;
350338
groupsIndex++;
351339
}
@@ -359,7 +347,7 @@ export class CodeLensContribution implements IEditorContribution {
359347

360348
// Create extra symbols
361349
while (groupsIndex < groups.length) {
362-
this._lenses.push(new CodeLensWidget(groups[groupsIndex], <IActiveCodeEditor>this._editor, this._styleClassName, helper, viewZoneAccessor, layoutInfo.codeLensHeight, () => this._resolveCodeLensesInViewportSoon()));
350+
this._lenses.push(new CodeLensWidget(groups[groupsIndex], <IActiveCodeEditor>this._editor, helper, viewZoneAccessor, layoutInfo.codeLensHeight, () => this._resolveCodeLensesInViewportSoon()));
363351
groupsIndex++;
364352
}
365353

src/vs/editor/contrib/codelens/browser/codelensWidget.css

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
display: inline-block;
99
text-overflow: ellipsis;
1010
white-space: nowrap;
11-
color: var(--vscode-editorCodeLens-foreground)
11+
color: var(--vscode-editorCodeLens-foreground);
12+
line-height: var(--vscode-editorCodeLens-lineHeight);
13+
font-size: var(--vscode-editorCodeLens-fontSize);
14+
padding-right: calc(var(--vscode-editorCodeLens-fontSize)*0.5);
15+
font-feature-settings: var(--vscode-editorCodeLens-fontFeatureSettings);
16+
font-family: var(--vscode-editorCodeLens-fontFamily), var(--vscode-editorCodeLens-fontFamilyDefault);
1217
}
1318

1419
.monaco-editor .codelens-decoration>span,
@@ -36,6 +41,8 @@
3641
vertical-align: middle;
3742
color: currentColor !important;
3843
color: var(--vscode-editorCodeLens-foreground);
44+
line-height: var(--vscode-editorCodeLens-lineHeight);
45+
font-size: var(--vscode-editorCodeLens-fontSize);
3946
}
4047

4148
.monaco-editor .codelens-decoration>a:hover .codicon::before {

src/vs/editor/contrib/codelens/browser/codelensWidget.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ class CodeLensContentWidget implements IContentWidget {
7272

7373
constructor(
7474
editor: IActiveCodeEditor,
75-
className: string,
7675
line: number,
7776
) {
7877
this._editor = editor;
@@ -81,7 +80,7 @@ class CodeLensContentWidget implements IContentWidget {
8180
this.updatePosition(line);
8281

8382
this._domNode = document.createElement('span');
84-
this._domNode.className = `codelens-decoration ${className}`;
83+
this._domNode.className = `codelens-decoration`;
8584
}
8685

8786
withCommands(lenses: Array<CodeLens | undefined | null>, animate: boolean): void {
@@ -186,7 +185,6 @@ export class CodeLensHelper {
186185
export class CodeLensWidget {
187186

188187
private readonly _editor: IActiveCodeEditor;
189-
private readonly _className: string;
190188
private readonly _viewZone: CodeLensViewZone;
191189
private readonly _viewZoneId: string;
192190

@@ -198,14 +196,12 @@ export class CodeLensWidget {
198196
constructor(
199197
data: CodeLensItem[],
200198
editor: IActiveCodeEditor,
201-
className: string,
202199
helper: CodeLensHelper,
203200
viewZoneChangeAccessor: IViewZoneChangeAccessor,
204201
heightInPx: number,
205202
updateCallback: () => void
206203
) {
207204
this._editor = editor;
208-
this._className = className;
209205
this._data = data;
210206

211207
// create combined range, track all ranges with decorations,
@@ -244,7 +240,7 @@ export class CodeLensWidget {
244240

245241
private _createContentWidgetIfNecessary(): void {
246242
if (!this._contentWidget) {
247-
this._contentWidget = new CodeLensContentWidget(this._editor, this._className, this._viewZone.afterLineNumber + 1);
243+
this._contentWidget = new CodeLensContentWidget(this._editor, this._viewZone.afterLineNumber + 1);
248244
this._editor.addContentWidget(this._contentWidget);
249245
} else {
250246
this._editor.layoutContentWidget(this._contentWidget);

0 commit comments

Comments
 (0)