@@ -33,7 +33,7 @@ class StickyScrollController implements IEditorContribution {
33
33
private readonly _store : DisposableStore = new DisposableStore ( ) ;
34
34
private readonly _sessionStore : DisposableStore = new DisposableStore ( ) ;
35
35
36
- private _ranges : any [ ] [ ] = [ ] ;
36
+ private _ranges : [ number , number , number ] [ ] = [ ] ;
37
37
private _cts : CancellationTokenSource | undefined ;
38
38
private _lastScrollPosition : number = - 1 ;
39
39
@@ -156,7 +156,7 @@ class StickyScrollController implements IEditorContribution {
156
156
return ;
157
157
}
158
158
159
- const lineHeight = this . _editor . getOption ( EditorOption . lineHeight ) ;
159
+ const lineHeight : number = this . _editor . getOption ( EditorOption . lineHeight ) ;
160
160
const model = this . _editor . getModel ( ) ;
161
161
162
162
const scrollTop = this . _editor . getScrollTop ( ) ;
@@ -168,26 +168,35 @@ class StickyScrollController implements IEditorContribution {
168
168
}
169
169
this . _lastScrollPosition = scrollTop ;
170
170
171
- const scrollTopFromLengthOfArray : number = this . _editor . getScrollTop ( ) + this . stickyScrollWidget . codeLineCount * lineHeight + 1 ;
171
+ const scrollToBottomOfWidget = this . _editor . getScrollTop ( ) + this . stickyScrollWidget . codeLineCount * lineHeight ;
172
172
this . stickyScrollWidget . emptyRootNode ( ) ;
173
- const beginningLinesConsidered = new Set ( ) ;
173
+ const beginningLinesConsidered : Set < number > = new Set < number > ( ) ;
174
+ let topOfElementAtDepth : number ;
175
+ let bottomOfElementAtDepth : number ;
176
+ let bottomOfBeginningLine : number ;
177
+ let topOfEndLine : number ;
178
+ let bottomOfEndLine : number ;
174
179
175
180
for ( const [ index , arr ] of this . _ranges . entries ( ) ) {
176
181
const [ start , end , depth ] = arr ;
177
- const scrollTopFromDepth : number = this . _editor . getScrollTop ( ) + depth * lineHeight + 1 ;
182
+ topOfElementAtDepth = this . _editor . getScrollTop ( ) + ( depth - 1 ) * lineHeight ;
183
+ bottomOfElementAtDepth = this . _editor . getScrollTop ( ) + depth * lineHeight ;
184
+ bottomOfBeginningLine = start * lineHeight ;
185
+ topOfEndLine = ( end - 1 ) * lineHeight ;
186
+ bottomOfEndLine = end * lineHeight ;
178
187
179
188
if ( ! beginningLinesConsidered . has ( start ) ) {
180
- if ( this . _editor . getScrollTop ( ) + ( depth - 1 ) * lineHeight + 1 >= ( end - 1 ) * lineHeight && this . _editor . getScrollTop ( ) + ( depth - 1 ) * lineHeight < end * lineHeight - 2 ) {
189
+ if ( topOfElementAtDepth >= topOfEndLine - 1 && topOfElementAtDepth < bottomOfEndLine - 2 ) {
181
190
beginningLinesConsidered . add ( start ) ;
182
- this . stickyScrollWidget . pushCodeLine ( new StickyScrollCodeLine ( model . getLineContent ( start ) , start , this . _editor , - 1 , ( depth - 1 ) * lineHeight + end * lineHeight - this . _editor . getScrollTop ( ) - depth * lineHeight ) ) ;
191
+ this . stickyScrollWidget . pushCodeLine ( new StickyScrollCodeLine ( model . getLineContent ( start ) , start , this . _editor , - 1 , ( depth - 1 ) * lineHeight + bottomOfEndLine - bottomOfElementAtDepth ) ) ;
183
192
break ;
184
193
}
185
- else if ( scrollDirection === ScrollDirection . Down && scrollTopFromDepth > start * lineHeight && scrollTopFromDepth < end * lineHeight ) {
194
+ else if ( scrollDirection === ScrollDirection . Down && bottomOfElementAtDepth > bottomOfBeginningLine - 1 && bottomOfElementAtDepth < bottomOfEndLine - 1 ) {
186
195
beginningLinesConsidered . add ( start ) ;
187
196
this . stickyScrollWidget . pushCodeLine ( new StickyScrollCodeLine ( model . getLineContent ( start ) , start , this . _editor , 0 ) ) ;
188
197
189
- } else if ( scrollDirection === ScrollDirection . Up && scrollTopFromLengthOfArray > start * lineHeight && scrollTopFromLengthOfArray < end * lineHeight ||
190
- scrollDirection === ScrollDirection . Up && scrollTopFromDepth >= start * lineHeight && scrollTopFromDepth < ( end - 1 ) * lineHeight ) {
198
+ } else if ( scrollDirection === ScrollDirection . Up && scrollToBottomOfWidget > bottomOfBeginningLine - 1 && scrollToBottomOfWidget < bottomOfEndLine ||
199
+ scrollDirection === ScrollDirection . Up && bottomOfElementAtDepth > bottomOfBeginningLine && bottomOfElementAtDepth < topOfEndLine - 1 ) {
191
200
beginningLinesConsidered . add ( start ) ;
192
201
this . stickyScrollWidget . pushCodeLine ( new StickyScrollCodeLine ( model . getLineContent ( start ) , start , this . _editor , 0 ) ) ;
193
202
}
@@ -236,19 +245,19 @@ class StickyScrollCodeLine {
236
245
lineHTMLNode . style . paddingLeft = this . _editor . getLayoutInfo ( ) . contentLeft - this . _editor . getLayoutInfo ( ) . lineNumbersLeft - this . _editor . getLayoutInfo ( ) . lineNumbersWidth + 'px' ;
237
246
lineHTMLNode . style . float = 'left' ;
238
247
lineHTMLNode . style . width = this . _editor . getLayoutInfo ( ) . width - this . _editor . getLayoutInfo ( ) . contentLeft + 'px' ;
239
- lineHTMLNode . style . backgroundColor = `var(--vscode-stickyScroll -background)` ;
248
+ lineHTMLNode . style . backgroundColor = `var(--vscode-editorStickyScroll -background)` ;
240
249
lineHTMLNode . innerHTML = newLine as string ;
241
250
242
251
const lineNumberHTMLNode = document . createElement ( 'div' ) ;
243
252
lineNumberHTMLNode . style . width = this . _editor . getLayoutInfo ( ) . contentLeft . toString ( ) + 'px' ;
244
- lineNumberHTMLNode . style . backgroundColor = `var(--vscode-stickyScroll -background)` ;
253
+ lineNumberHTMLNode . style . backgroundColor = `var(--vscode-editorStickyScroll -background)` ;
245
254
lineNumberHTMLNode . style . color = 'var(--vscode-editorLineNumber-foreground)' ;
246
255
247
256
const innerLineNumberHTML = document . createElement ( 'div' ) ;
248
257
innerLineNumberHTML . innerText = this . _lineNumber . toString ( ) ;
249
258
innerLineNumberHTML . style . paddingLeft = this . _editor . getLayoutInfo ( ) . lineNumbersLeft . toString ( ) + 'px' ;
250
259
innerLineNumberHTML . style . width = this . _editor . getLayoutInfo ( ) . lineNumbersWidth . toString ( ) + 'px' ;
251
- innerLineNumberHTML . style . backgroundColor = `var(--vscode-stickyScroll -background)` ;
260
+ innerLineNumberHTML . style . backgroundColor = `var(--vscode-editorStickyScroll -background)` ;
252
261
innerLineNumberHTML . style . textAlign = 'right' ;
253
262
innerLineNumberHTML . style . float = 'left' ;
254
263
lineNumberHTMLNode . appendChild ( innerLineNumberHTML ) ;
@@ -259,14 +268,14 @@ class StickyScrollCodeLine {
259
268
this . _editor . revealLine ( this . _lineNumber ) ;
260
269
} ;
261
270
lineHTMLNode . onmouseover = e => {
262
- innerLineNumberHTML . style . background = `var(--vscode-stickyScrollHover -background)` ;
263
- lineHTMLNode . style . backgroundColor = `var(--vscode-stickyScrollHover -background)` ;
271
+ innerLineNumberHTML . style . background = `var(--vscode-editorStickyScrollHover -background)` ;
272
+ lineHTMLNode . style . backgroundColor = `var(--vscode-editorStickyScrollHover -background)` ;
264
273
innerLineNumberHTML . style . cursor = `pointer` ;
265
274
lineHTMLNode . style . cursor = `pointer` ;
266
275
} ;
267
276
lineHTMLNode . onmouseleave = e => {
268
- innerLineNumberHTML . style . background = `var(--vscode-stickyScroll -background)` ;
269
- lineHTMLNode . style . backgroundColor = `var(--vscode-stickyScroll -background)` ;
277
+ innerLineNumberHTML . style . background = `var(--vscode-editorStickyScroll -background)` ;
278
+ lineHTMLNode . style . backgroundColor = `var(--vscode-editorStickyScroll -background)` ;
270
279
} ;
271
280
272
281
this . _editor . applyFontInfo ( lineHTMLNode ) ;
@@ -276,7 +285,7 @@ class StickyScrollCodeLine {
276
285
root . appendChild ( lineHTMLNode ) ;
277
286
278
287
root . style . zIndex = this . _zIndex . toString ( ) ;
279
- root . style . backgroundColor = `var(--vscode-stickyScroll -background)` ;
288
+ root . style . backgroundColor = `var(--vscode-editorStickyScroll -background)` ;
280
289
281
290
// Special case for last line of sticky scroll
282
291
if ( this . _position ) {
@@ -323,7 +332,7 @@ class StickyScrollWidget implements IOverlayWidget {
323
332
324
333
getDomNode ( ) : HTMLElement {
325
334
this . rootDomNode . style . zIndex = '2' ;
326
- this . rootDomNode . style . backgroundColor = `var(--vscode-stickyScroll -background)` ;
335
+ this . rootDomNode . style . backgroundColor = `var(--vscode-editorStickyScroll -background)` ;
327
336
return this . rootDomNode ;
328
337
}
329
338
0 commit comments