@@ -19,12 +19,6 @@ import { LineDecoration } from 'vs/editor/common/viewLayout/lineDecorations';
19
19
import { RunOnceScheduler } from 'vs/base/common/async' ;
20
20
import { IModelTokensChangedEvent } from 'vs/editor/common/textModelEvents' ;
21
21
22
- const enum ScrollDirection {
23
- Down = 0 ,
24
- Up = 1 ,
25
- None = 2
26
- }
27
-
28
22
class StickyScrollController extends Disposable implements IEditorContribution {
29
23
30
24
static readonly ID = 'store.contrib.stickyScrollController' ;
@@ -36,7 +30,6 @@ class StickyScrollController extends Disposable implements IEditorContribution {
36
30
private _ranges : [ number , number , number ] [ ] = [ ] ;
37
31
private _rangesVersionId : number = 0 ;
38
32
private _cts : CancellationTokenSource | undefined ;
39
- private _lastScrollPosition : number = - 1 ;
40
33
private readonly _updateSoon : RunOnceScheduler ;
41
34
42
35
constructor (
@@ -191,42 +184,27 @@ class StickyScrollController extends Disposable implements IEditorContribution {
191
184
return ;
192
185
}
193
186
const scrollTop = this . _editor . getScrollTop ( ) ;
194
- let scrollDirection : ScrollDirection ;
195
- if ( this . _lastScrollPosition < scrollTop ) {
196
- scrollDirection = ScrollDirection . Down ;
197
- } else {
198
- scrollDirection = ScrollDirection . Up ;
199
- }
200
- this . _lastScrollPosition = scrollTop ;
201
187
202
- const scrollToBottomOfWidget = this . _editor . getScrollTop ( ) + this . stickyScrollWidget . codeLineCount * lineHeight ;
203
188
this . stickyScrollWidget . emptyRootNode ( ) ;
204
189
const beginningLinesConsidered : Set < number > = new Set < number > ( ) ;
205
- let topOfElementAtDepth : number ;
206
- let bottomOfElementAtDepth : number ;
207
- let bottomOfBeginningLine : number ;
208
- let topOfEndLine : number ;
209
- let bottomOfEndLine : number ;
210
190
211
191
for ( const [ index , arr ] of this . _ranges . entries ( ) ) {
212
192
const [ start , end , depth ] = arr ;
213
193
if ( end - start > 0 && model . getLineContent ( start ) !== '' ) {
214
- topOfElementAtDepth = this . _editor . getScrollTop ( ) + ( depth - 1 ) * lineHeight ;
215
- bottomOfElementAtDepth = this . _editor . getScrollTop ( ) + depth * lineHeight ;
216
- bottomOfBeginningLine = start * lineHeight ;
217
- topOfEndLine = ( end - 1 ) * lineHeight ;
218
- bottomOfEndLine = end * lineHeight ;
194
+ const topOfElementAtDepth = ( depth - 1 ) * lineHeight ;
195
+ const bottomOfElementAtDepth = depth * lineHeight ;
196
+
197
+ const bottomOfBeginningLine = this . _editor . getBottomForLineNumber ( start ) - scrollTop ;
198
+ const topOfEndLine = this . _editor . getTopForLineNumber ( end ) - scrollTop ;
199
+ const bottomOfEndLine = this . _editor . getBottomForLineNumber ( end ) - scrollTop ;
200
+
219
201
if ( ! beginningLinesConsidered . has ( start ) ) {
220
202
if ( topOfElementAtDepth >= topOfEndLine - 1 && topOfElementAtDepth < bottomOfEndLine - 2 ) {
221
203
beginningLinesConsidered . add ( start ) ;
222
204
this . stickyScrollWidget . pushCodeLine ( new StickyScrollCodeLine ( model . getLineContent ( start ) , start , this . _editor , - 1 , bottomOfEndLine - bottomOfElementAtDepth ) ) ;
223
205
break ;
224
206
}
225
- else if ( scrollDirection === ScrollDirection . Down && bottomOfElementAtDepth > bottomOfBeginningLine - 1 && bottomOfElementAtDepth < bottomOfEndLine - 1 ) {
226
- beginningLinesConsidered . add ( start ) ;
227
- this . stickyScrollWidget . pushCodeLine ( new StickyScrollCodeLine ( model . getLineContent ( start ) , start , this . _editor , 0 , 0 ) ) ;
228
- } else if ( scrollDirection === ScrollDirection . Up && scrollToBottomOfWidget > bottomOfBeginningLine - 1 && scrollToBottomOfWidget < bottomOfEndLine ||
229
- scrollDirection === ScrollDirection . Up && bottomOfElementAtDepth > bottomOfBeginningLine && bottomOfElementAtDepth < topOfEndLine - 1 ) {
207
+ else if ( bottomOfElementAtDepth > bottomOfBeginningLine - 1 && bottomOfElementAtDepth < bottomOfEndLine - 1 ) {
230
208
beginningLinesConsidered . add ( start ) ;
231
209
this . stickyScrollWidget . pushCodeLine ( new StickyScrollCodeLine ( model . getLineContent ( start ) , start , this . _editor , 0 , 0 ) ) ;
232
210
}
@@ -262,7 +240,7 @@ class StickyScrollCodeLine {
262
240
getDomNode ( ) {
263
241
264
242
const root : HTMLElement = document . createElement ( 'div' ) ;
265
- const lineRenderingData = this . _editor . _getViewModel ( ) . getViewLineRenderingData ( this . _editor . getVisibleRangesPlusViewportAboveBelow ( ) [ 0 ] , this . _lineNumber ) ;
243
+ const lineRenderingData = this . _editor . _getViewModel ( ) . getViewportViewLineRenderingData ( this . _editor . getVisibleRangesPlusViewportAboveBelow ( ) [ 0 ] , this . _lineNumber ) ;
266
244
267
245
let actualInlineDecorations : LineDecoration [ ] ;
268
246
try {
0 commit comments