@@ -16,49 +16,59 @@ import { IModelTokensChangedEvent } from 'vs/editor/common/textModelEvents';
16
16
export class StickyScrollController extends Disposable implements IEditorContribution {
17
17
18
18
static readonly ID = 'store.contrib.stickyScrollController' ;
19
- private readonly editor : ICodeEditor ;
20
- private readonly stickyScrollWidget : StickyScrollWidget ;
21
- private readonly stickyLineCandidateProvider : StickyLineCandidateProvider ;
22
- private readonly sessionStore : DisposableStore = new DisposableStore ( ) ;
19
+ private readonly _editor : ICodeEditor ;
20
+ private readonly _stickyScrollWidget : StickyScrollWidget ;
21
+ private readonly _stickyLineCandidateProvider : StickyLineCandidateProvider ;
22
+ private readonly _sessionStore : DisposableStore = new DisposableStore ( ) ;
23
+ private _widgetState : StickyScrollWidgetState ;
23
24
24
25
constructor (
25
26
editor : ICodeEditor ,
26
- @ILanguageFeaturesService _languageFeaturesService : ILanguageFeaturesService ,
27
+ @ILanguageFeaturesService languageFeaturesService : ILanguageFeaturesService ,
27
28
) {
28
29
super ( ) ;
29
- this . editor = editor ;
30
- this . stickyScrollWidget = new StickyScrollWidget ( this . editor ) ;
31
- this . stickyLineCandidateProvider = new StickyLineCandidateProvider ( this . editor , _languageFeaturesService ) ;
30
+ this . _editor = editor ;
31
+ this . _stickyScrollWidget = new StickyScrollWidget ( this . _editor ) ;
32
+ this . _stickyLineCandidateProvider = new StickyLineCandidateProvider ( this . _editor , languageFeaturesService ) ;
33
+ this . _widgetState = new StickyScrollWidgetState ( [ ] , 0 ) ;
32
34
33
- this . _register ( this . editor . onDidChangeConfiguration ( e => {
35
+ this . _register ( this . _editor . onDidChangeConfiguration ( e => {
34
36
if ( e . hasChanged ( EditorOption . experimental ) ) {
35
37
this . readConfiguration ( ) ;
36
38
}
37
39
} ) ) ;
38
40
this . readConfiguration ( ) ;
39
41
}
40
42
43
+ public get stickyScrollCandidateProvider ( ) {
44
+ return this . _stickyLineCandidateProvider ;
45
+ }
46
+
47
+ public get stickyScrollWidgetState ( ) {
48
+ return this . _widgetState ;
49
+ }
50
+
41
51
private readConfiguration ( ) {
42
- const options = this . editor . getOption ( EditorOption . experimental ) ;
52
+ const options = this . _editor . getOption ( EditorOption . experimental ) ;
43
53
if ( options . stickyScroll . enabled === false ) {
44
- this . editor . removeOverlayWidget ( this . stickyScrollWidget ) ;
45
- this . sessionStore . clear ( ) ;
54
+ this . _editor . removeOverlayWidget ( this . _stickyScrollWidget ) ;
55
+ this . _sessionStore . clear ( ) ;
46
56
return ;
47
57
} else {
48
- this . editor . addOverlayWidget ( this . stickyScrollWidget ) ;
49
- this . sessionStore . add ( this . editor . onDidScrollChange ( ( ) => this . renderStickyScroll ( ) ) ) ;
50
- this . sessionStore . add ( this . editor . onDidLayoutChange ( ( ) => this . onDidResize ( ) ) ) ;
51
- this . sessionStore . add ( this . editor . onDidChangeModelTokens ( ( e ) => this . onTokensChange ( e ) ) ) ;
52
- this . sessionStore . add ( this . stickyLineCandidateProvider . onStickyScrollChange ( ( ) => this . renderStickyScroll ( ) ) ) ;
53
- const lineNumberOption = this . editor . getOption ( EditorOption . lineNumbers ) ;
58
+ this . _editor . addOverlayWidget ( this . _stickyScrollWidget ) ;
59
+ this . _sessionStore . add ( this . _editor . onDidScrollChange ( ( ) => this . renderStickyScroll ( ) ) ) ;
60
+ this . _sessionStore . add ( this . _editor . onDidLayoutChange ( ( ) => this . onDidResize ( ) ) ) ;
61
+ this . _sessionStore . add ( this . _editor . onDidChangeModelTokens ( ( e ) => this . onTokensChange ( e ) ) ) ;
62
+ this . _sessionStore . add ( this . _stickyLineCandidateProvider . onStickyScrollChange ( ( ) => this . renderStickyScroll ( ) ) ) ;
63
+ const lineNumberOption = this . _editor . getOption ( EditorOption . lineNumbers ) ;
54
64
if ( lineNumberOption . renderType === RenderLineNumbersType . Relative ) {
55
- this . sessionStore . add ( this . editor . onDidChangeCursorPosition ( ( ) => this . renderStickyScroll ( ) ) ) ;
65
+ this . _sessionStore . add ( this . _editor . onDidChangeCursorPosition ( ( ) => this . renderStickyScroll ( ) ) ) ;
56
66
}
57
67
}
58
68
}
59
69
60
70
private needsUpdate ( event : IModelTokensChangedEvent ) {
61
- const stickyLineNumbers = this . stickyScrollWidget . getCurrentLines ( ) ;
71
+ const stickyLineNumbers = this . _stickyScrollWidget . getCurrentLines ( ) ;
62
72
for ( const stickyLineNumber of stickyLineNumbers ) {
63
73
for ( const range of event . ranges ) {
64
74
if ( stickyLineNumber >= range . fromLineNumber && stickyLineNumber <= range . toLineNumber ) {
@@ -76,31 +86,32 @@ export class StickyScrollController extends Disposable implements IEditorContrib
76
86
}
77
87
78
88
private onDidResize ( ) {
79
- const width = this . editor . getLayoutInfo ( ) . width - this . editor . getLayoutInfo ( ) . minimap . minimapCanvasOuterWidth - this . editor . getLayoutInfo ( ) . verticalScrollbarWidth ;
80
- this . stickyScrollWidget . getDomNode ( ) . style . width = `${ width } px` ;
89
+ const width = this . _editor . getLayoutInfo ( ) . width - this . _editor . getLayoutInfo ( ) . minimap . minimapCanvasOuterWidth - this . _editor . getLayoutInfo ( ) . verticalScrollbarWidth ;
90
+ this . _stickyScrollWidget . getDomNode ( ) . style . width = `${ width } px` ;
81
91
}
82
92
83
93
private renderStickyScroll ( ) {
84
- if ( ! ( this . editor . hasModel ( ) ) ) {
94
+ if ( ! ( this . _editor . hasModel ( ) ) ) {
85
95
return ;
86
96
}
87
- const model = this . editor . getModel ( ) ;
88
- if ( this . stickyLineCandidateProvider . getVersionId ( ) !== model . getVersionId ( ) ) {
97
+ const model = this . _editor . getModel ( ) ;
98
+ if ( this . _stickyLineCandidateProvider . getVersionId ( ) !== model . getVersionId ( ) ) {
89
99
// Old _ranges not updated yet
90
100
return ;
91
101
}
92
- this . stickyScrollWidget . setState ( this . getScrollWidgetState ( ) ) ;
102
+ this . _widgetState = this . getScrollWidgetState ( ) ;
103
+ this . _stickyScrollWidget . setState ( this . _widgetState ) ;
93
104
}
94
105
95
- private getScrollWidgetState ( ) : StickyScrollWidgetState {
96
- const lineHeight : number = this . editor . getOption ( EditorOption . lineHeight ) ;
97
- const scrollTop : number = this . editor . getScrollTop ( ) ;
106
+ public getScrollWidgetState ( ) : StickyScrollWidgetState {
107
+ const lineHeight : number = this . _editor . getOption ( EditorOption . lineHeight ) ;
108
+ const scrollTop : number = this . _editor . getScrollTop ( ) ;
98
109
let lastLineRelativePosition : number = 0 ;
99
110
const lineNumbers : number [ ] = [ ] ;
100
- const arrayVisibleRanges = this . editor . getVisibleRanges ( ) ;
111
+ const arrayVisibleRanges = this . _editor . getVisibleRanges ( ) ;
101
112
if ( arrayVisibleRanges . length !== 0 ) {
102
113
const fullVisibleRange = new StickyRange ( arrayVisibleRanges [ 0 ] . startLineNumber , arrayVisibleRanges [ arrayVisibleRanges . length - 1 ] . endLineNumber ) ;
103
- const candidateRanges = this . stickyLineCandidateProvider . getCandidateStickyLinesIntersecting ( fullVisibleRange ) ;
114
+ const candidateRanges = this . _stickyLineCandidateProvider . getCandidateStickyLinesIntersecting ( fullVisibleRange ) ;
104
115
for ( const range of candidateRanges ) {
105
116
const start = range . startLineNumber ;
106
117
const end = range . endLineNumber ;
@@ -109,9 +120,9 @@ export class StickyScrollController extends Disposable implements IEditorContrib
109
120
const topOfElementAtDepth = ( depth - 1 ) * lineHeight ;
110
121
const bottomOfElementAtDepth = depth * lineHeight ;
111
122
112
- const bottomOfBeginningLine = this . editor . getBottomForLineNumber ( start ) - scrollTop ;
113
- const topOfEndLine = this . editor . getTopForLineNumber ( end ) - scrollTop ;
114
- const bottomOfEndLine = this . editor . getBottomForLineNumber ( end ) - scrollTop ;
123
+ const bottomOfBeginningLine = this . _editor . getBottomForLineNumber ( start ) - scrollTop ;
124
+ const topOfEndLine = this . _editor . getTopForLineNumber ( end ) - scrollTop ;
125
+ const bottomOfEndLine = this . _editor . getBottomForLineNumber ( end ) - scrollTop ;
115
126
116
127
if ( topOfElementAtDepth > topOfEndLine && topOfElementAtDepth <= bottomOfEndLine ) {
117
128
lineNumbers . push ( start ) ;
@@ -129,7 +140,7 @@ export class StickyScrollController extends Disposable implements IEditorContrib
129
140
130
141
override dispose ( ) : void {
131
142
super . dispose ( ) ;
132
- this . sessionStore . dispose ( ) ;
143
+ this . _sessionStore . dispose ( ) ;
133
144
}
134
145
}
135
146
0 commit comments