3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import * as dom from 'vs/base/browser/dom' ;
6
+
7
7
import { CancelablePromise , createCancelablePromise , disposableTimeout , RunOnceScheduler } from 'vs/base/common/async' ;
8
8
import { onUnexpectedError , onUnexpectedExternalError } from 'vs/base/common/errors' ;
9
- import { hash } from 'vs/base/common/hash' ;
10
9
import { DisposableStore , toDisposable } from 'vs/base/common/lifecycle' ;
11
10
import { StableEditorScrollState } from 'vs/editor/browser/stableEditorScroll' ;
12
11
import { IActiveCodeEditor , ICodeEditor , IViewZoneChangeAccessor , MouseTargetType } from 'vs/editor/browser/editorBrowser' ;
@@ -32,8 +31,7 @@ export class CodeLensContribution implements IEditorContribution {
32
31
33
32
private readonly _disposables = new DisposableStore ( ) ;
34
33
private readonly _localToDispose = new DisposableStore ( ) ;
35
- private readonly _styleElement : HTMLStyleElement ;
36
- private readonly _styleClassName : string ;
34
+
37
35
private readonly _lenses : CodeLensWidget [ ] = [ ] ;
38
36
39
37
private readonly _provideCodeLensDebounce : IFeatureDebounceInformation ;
@@ -70,12 +68,6 @@ export class CodeLensContribution implements IEditorContribution {
70
68
this . _disposables . add ( _languageFeaturesService . codeLensProvider . onDidChange ( this . _onModelChange , this ) ) ;
71
69
this . _onModelChange ( ) ;
72
70
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
- ) ;
79
71
this . _updateLensStyle ( ) ;
80
72
}
81
73
@@ -84,7 +76,6 @@ export class CodeLensContribution implements IEditorContribution {
84
76
this . _disposables . dispose ( ) ;
85
77
this . _oldCodeLensModels . dispose ( ) ;
86
78
this . _currentCodeLensModel ?. dispose ( ) ;
87
- this . _styleElement . remove ( ) ;
88
79
}
89
80
90
81
private _getLayoutInfo ( ) {
@@ -105,19 +96,16 @@ export class CodeLensContribution implements IEditorContribution {
105
96
const fontFamily = this . _editor . getOption ( EditorOption . codeLensFontFamily ) ;
106
97
const editorFontInfo = this . _editor . getOption ( EditorOption . fontInfo ) ;
107
98
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 ) ;
110
104
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
- ` ;
115
105
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 ) ;
117
108
}
118
- this . _styleElement . textContent = newStyle ;
119
- this . _editor . getContainerDomNode ( ) . style . setProperty ( fontFamilyVar , fontFamily ?? 'inherit' ) ;
120
- this . _editor . getContainerDomNode ( ) . style . setProperty ( fontFeaturesVar , editorFontInfo . fontFeatureSettings ) ;
121
109
122
110
//
123
111
this . _editor . changeViewZones ( accessor => {
@@ -345,7 +333,7 @@ export class CodeLensContribution implements IEditorContribution {
345
333
groupsIndex ++ ;
346
334
codeLensIndex ++ ;
347
335
} 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 ( ) ) ) ;
349
337
codeLensIndex ++ ;
350
338
groupsIndex ++ ;
351
339
}
@@ -359,7 +347,7 @@ export class CodeLensContribution implements IEditorContribution {
359
347
360
348
// Create extra symbols
361
349
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 ( ) ) ) ;
363
351
groupsIndex ++ ;
364
352
}
365
353
0 commit comments