@@ -19,6 +19,7 @@ import { LineDecoration } from '../../../common/viewLayout/lineDecorations.js';
19
19
import { CharacterMapping , RenderLineInput , renderViewLine } from '../../../common/viewLayout/viewLineRenderer.js' ;
20
20
import { foldingCollapsedIcon , foldingExpandedIcon } from '../../folding/browser/foldingDecorations.js' ;
21
21
import { FoldingModel } from '../../folding/browser/foldingModel.js' ;
22
+ import { Emitter } from '../../../../base/common/event.js' ;
22
23
23
24
export class StickyScrollWidgetState {
24
25
constructor (
@@ -62,6 +63,12 @@ export class StickyScrollWidget extends Disposable implements IOverlayWidget {
62
63
private _lastLineRelativePosition : number = 0 ;
63
64
private _minContentWidthInPx : number = 0 ;
64
65
private _isOnGlyphMargin : boolean = false ;
66
+ private _height : number = - 1 ;
67
+
68
+ public get height ( ) : number { return this . _height ; }
69
+
70
+ private readonly _onDidChangeStickyScrollHeight = this . _register ( new Emitter < { height : number } > ( ) ) ;
71
+ public readonly onDidChangeStickyScrollHeight = this . _onDidChangeStickyScrollHeight . event ;
65
72
66
73
constructor (
67
74
private readonly _editor : ICodeEditor
@@ -81,6 +88,7 @@ export class StickyScrollWidget extends Disposable implements IOverlayWidget {
81
88
this . _rootDomNode . classList . toggle ( 'peek' , _editor instanceof EmbeddedCodeEditorWidget ) ;
82
89
this . _rootDomNode . appendChild ( this . _lineNumbersDomNode ) ;
83
90
this . _rootDomNode . appendChild ( this . _linesDomNodeScrollable ) ;
91
+ this . _setHeight ( 0 ) ;
84
92
85
93
const updateScrollLeftPosition = ( ) => {
86
94
this . _linesDomNode . style . left = this . _editor . getOption ( EditorOption . stickyScroll ) . scrollWithEditor ? `-${ this . _editor . getScrollLeft ( ) } px` : '0px' ;
@@ -193,7 +201,6 @@ export class StickyScrollWidget extends Disposable implements IOverlayWidget {
193
201
}
194
202
// Keep the lines that need to be updated
195
203
this . _renderedStickyLines = this . _renderedStickyLines . slice ( 0 , clearFromLine ) ;
196
- this . _rootDomNode . style . display = 'none' ;
197
204
}
198
205
199
206
private _useFoldingOpacityTransition ( requireTransitions : boolean ) {
@@ -213,6 +220,8 @@ export class StickyScrollWidget extends Disposable implements IOverlayWidget {
213
220
private async _renderRootNode ( state : StickyScrollWidgetState | undefined , foldingModel : FoldingModel | undefined , rebuildFromLine : number ) : Promise < void > {
214
221
this . _clearStickyLinesFromLine ( rebuildFromLine ) ;
215
222
if ( ! state ) {
223
+ // make sure the dom is 0 height and display:none
224
+ this . _setHeight ( 0 ) ;
216
225
return ;
217
226
}
218
227
// For existing sticky lines update the top and z-index
@@ -237,16 +246,31 @@ export class StickyScrollWidget extends Disposable implements IOverlayWidget {
237
246
}
238
247
239
248
const widgetHeight = this . _lineNumbers . length * this . _lineHeight + this . _lastLineRelativePosition ;
240
- this . _rootDomNode . style . display = 'block' ;
241
- this . _lineNumbersDomNode . style . height = `${ widgetHeight } px` ;
242
- this . _linesDomNodeScrollable . style . height = `${ widgetHeight } px` ;
243
- this . _rootDomNode . style . height = `${ widgetHeight } px` ;
249
+ this . _setHeight ( widgetHeight ) ;
244
250
245
251
this . _rootDomNode . style . marginLeft = '0px' ;
246
252
this . _minContentWidthInPx = Math . max ( ...this . _renderedStickyLines . map ( l => l . scrollWidth ) ) + layoutInfo . verticalScrollbarWidth ;
247
253
this . _editor . layoutOverlayWidget ( this ) ;
248
254
}
249
255
256
+ private _setHeight ( height : number ) : void {
257
+ if ( this . _height === height ) {
258
+ return ;
259
+ }
260
+ this . _height = height ;
261
+
262
+ if ( this . _height === 0 ) {
263
+ this . _rootDomNode . style . display = 'none' ;
264
+ } else {
265
+ this . _rootDomNode . style . display = 'block' ;
266
+ this . _lineNumbersDomNode . style . height = `${ this . _height } px` ;
267
+ this . _linesDomNodeScrollable . style . height = `${ this . _height } px` ;
268
+ this . _rootDomNode . style . height = `${ this . _height } px` ;
269
+ }
270
+
271
+ this . _onDidChangeStickyScrollHeight . fire ( { height : this . _height } ) ;
272
+ }
273
+
250
274
private _setFoldingHoverListeners ( ) : void {
251
275
const showFoldingControls : 'mouseover' | 'always' | 'never' = this . _editor . getOption ( EditorOption . showFoldingControls ) ;
252
276
if ( showFoldingControls !== 'mouseover' ) {
0 commit comments