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