Skip to content

Commit 930de55

Browse files
author
aiday-mar
committed
Work in progress
1 parent 22c1836 commit 930de55

File tree

4 files changed

+346
-119
lines changed

4 files changed

+346
-119
lines changed

src/vs/editor/contrib/stickyScroll/browser/stickyScroll.ts

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,59 @@ import { IModelTokensChangedEvent } from 'vs/editor/common/textModelEvents';
1616
export class StickyScrollController extends Disposable implements IEditorContribution {
1717

1818
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;
2324

2425
constructor(
2526
editor: ICodeEditor,
26-
@ILanguageFeaturesService _languageFeaturesService: ILanguageFeaturesService,
27+
@ILanguageFeaturesService languageFeaturesService: ILanguageFeaturesService,
2728
) {
2829
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);
3234

33-
this._register(this.editor.onDidChangeConfiguration(e => {
35+
this._register(this._editor.onDidChangeConfiguration(e => {
3436
if (e.hasChanged(EditorOption.experimental)) {
3537
this.readConfiguration();
3638
}
3739
}));
3840
this.readConfiguration();
3941
}
4042

43+
public get stickyScrollCandidateProvider() {
44+
return this._stickyLineCandidateProvider;
45+
}
46+
47+
public get stickyScrollWidgetState() {
48+
return this._widgetState;
49+
}
50+
4151
private readConfiguration() {
42-
const options = this.editor.getOption(EditorOption.experimental);
52+
const options = this._editor.getOption(EditorOption.experimental);
4353
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();
4656
return;
4757
} 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);
5464
if (lineNumberOption.renderType === RenderLineNumbersType.Relative) {
55-
this.sessionStore.add(this.editor.onDidChangeCursorPosition(() => this.renderStickyScroll()));
65+
this._sessionStore.add(this._editor.onDidChangeCursorPosition(() => this.renderStickyScroll()));
5666
}
5767
}
5868
}
5969

6070
private needsUpdate(event: IModelTokensChangedEvent) {
61-
const stickyLineNumbers = this.stickyScrollWidget.getCurrentLines();
71+
const stickyLineNumbers = this._stickyScrollWidget.getCurrentLines();
6272
for (const stickyLineNumber of stickyLineNumbers) {
6373
for (const range of event.ranges) {
6474
if (stickyLineNumber >= range.fromLineNumber && stickyLineNumber <= range.toLineNumber) {
@@ -76,31 +86,32 @@ export class StickyScrollController extends Disposable implements IEditorContrib
7686
}
7787

7888
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`;
8191
}
8292

8393
private renderStickyScroll() {
84-
if (!(this.editor.hasModel())) {
94+
if (!(this._editor.hasModel())) {
8595
return;
8696
}
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()) {
8999
// Old _ranges not updated yet
90100
return;
91101
}
92-
this.stickyScrollWidget.setState(this.getScrollWidgetState());
102+
this._widgetState = this.getScrollWidgetState();
103+
this._stickyScrollWidget.setState(this._widgetState);
93104
}
94105

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();
98109
let lastLineRelativePosition: number = 0;
99110
const lineNumbers: number[] = [];
100-
const arrayVisibleRanges = this.editor.getVisibleRanges();
111+
const arrayVisibleRanges = this._editor.getVisibleRanges();
101112
if (arrayVisibleRanges.length !== 0) {
102113
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);
104115
for (const range of candidateRanges) {
105116
const start = range.startLineNumber;
106117
const end = range.endLineNumber;
@@ -109,9 +120,9 @@ export class StickyScrollController extends Disposable implements IEditorContrib
109120
const topOfElementAtDepth = (depth - 1) * lineHeight;
110121
const bottomOfElementAtDepth = depth * lineHeight;
111122

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;
115126

116127
if (topOfElementAtDepth > topOfEndLine && topOfElementAtDepth <= bottomOfEndLine) {
117128
lineNumbers.push(start);
@@ -129,7 +140,7 @@ export class StickyScrollController extends Disposable implements IEditorContrib
129140

130141
override dispose(): void {
131142
super.dispose();
132-
this.sessionStore.dispose();
143+
this._sessionStore.dispose();
133144
}
134145
}
135146

src/vs/editor/contrib/stickyScroll/browser/stickyScrollProvider.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,24 @@ export class StickyLineCandidateProvider extends Disposable {
3333
public readonly onStickyScrollChange = this.onStickyScrollChangeEmitter.event;
3434

3535
static readonly ID = 'store.contrib.stickyScrollController';
36-
private readonly editor: ICodeEditor;
37-
private readonly languageFeaturesService: ILanguageFeaturesService;
38-
private readonly updateSoon: RunOnceScheduler;
36+
private readonly _editor: ICodeEditor;
37+
private readonly _languageFeaturesService: ILanguageFeaturesService;
38+
private readonly _updateSoon: RunOnceScheduler;
3939

40-
private cts: CancellationTokenSource | undefined;
41-
private outlineModel: StickyOutlineElement | undefined;
42-
private readonly sessionStore: DisposableStore = new DisposableStore();
43-
private modelVersionId: number = 0;
40+
private _cts: CancellationTokenSource | undefined;
41+
private _outlineModel: StickyOutlineElement | undefined;
42+
private readonly _sessionStore: DisposableStore = new DisposableStore();
43+
private _modelVersionId: number = 0;
4444

4545
constructor(
4646
editor: ICodeEditor,
47-
@ILanguageFeaturesService _languageFeaturesService: ILanguageFeaturesService,
47+
@ILanguageFeaturesService languageFeaturesService: ILanguageFeaturesService,
4848
) {
4949
super();
50-
this.editor = editor;
51-
this.languageFeaturesService = _languageFeaturesService;
52-
this.updateSoon = this._register(new RunOnceScheduler(() => this.update(), 50));
53-
this._register(this.editor.onDidChangeConfiguration(e => {
50+
this._editor = editor;
51+
this._languageFeaturesService = languageFeaturesService;
52+
this._updateSoon = this._register(new RunOnceScheduler(() => this.update(), 50));
53+
this._register(this._editor.onDidChangeConfiguration(e => {
5454
if (e.hasChanged(EditorOption.experimental)) {
5555
this.readConfiguration();
5656
}
@@ -59,40 +59,40 @@ export class StickyLineCandidateProvider extends Disposable {
5959
}
6060

6161
private readConfiguration() {
62-
const options = this.editor.getOption(EditorOption.experimental);
62+
const options = this._editor.getOption(EditorOption.experimental);
6363
if (options.stickyScroll.enabled === false) {
64-
this.sessionStore.clear();
64+
this._sessionStore.clear();
6565
return;
6666
} else {
67-
this.sessionStore.add(this.editor.onDidChangeModel(() => this.update()));
68-
this.sessionStore.add(this.editor.onDidChangeHiddenAreas(() => this.update()));
69-
this.sessionStore.add(this.editor.onDidChangeModelContent(() => this.updateSoon.schedule()));
70-
this.sessionStore.add(this.languageFeaturesService.documentSymbolProvider.onDidChange(() => this.update()));
67+
this._sessionStore.add(this._editor.onDidChangeModel(() => this.update()));
68+
this._sessionStore.add(this._editor.onDidChangeHiddenAreas(() => this.update()));
69+
this._sessionStore.add(this._editor.onDidChangeModelContent(() => this._updateSoon.schedule()));
70+
this._sessionStore.add(this._languageFeaturesService.documentSymbolProvider.onDidChange(() => this.update()));
7171
this.update();
7272
}
7373
}
7474

7575
public getVersionId() {
76-
return this.modelVersionId;
76+
return this._modelVersionId;
7777
}
7878

79-
private async update(): Promise<void> {
80-
this.cts?.dispose(true);
81-
this.cts = new CancellationTokenSource();
82-
await this.updateOutlineModel(this.cts.token);
79+
public async update(): Promise<void> {
80+
this._cts?.dispose(true);
81+
this._cts = new CancellationTokenSource();
82+
await this.updateOutlineModel(this._cts.token);
8383
this.onStickyScrollChangeEmitter.fire();
8484
}
8585

8686
private async updateOutlineModel(token: CancellationToken) {
87-
if (this.editor.hasModel()) {
88-
const model = this.editor.getModel();
87+
if (this._editor.hasModel()) {
88+
const model = this._editor.getModel();
8989
const modelVersionId = model.getVersionId();
90-
const outlineModel = await OutlineModel.create(this.languageFeaturesService.documentSymbolProvider, model, token) as OutlineModel;
90+
const outlineModel = await OutlineModel.create(this._languageFeaturesService.documentSymbolProvider, model, token) as OutlineModel;
9191
if (token.isCancellationRequested) {
9292
return;
9393
}
94-
this.outlineModel = StickyOutlineElement.fromOutlineModel(outlineModel);
95-
this.modelVersionId = modelVersionId;
94+
this._outlineModel = StickyOutlineElement.fromOutlineModel(outlineModel);
95+
this._modelVersionId = modelVersionId;
9696
}
9797
}
9898

@@ -115,8 +115,8 @@ export class StickyLineCandidateProvider extends Disposable {
115115

116116
public getCandidateStickyLinesIntersecting(range: StickyRange): StickyLineCandidate[] {
117117
let stickyLineCandidates: StickyLineCandidate[] = [];
118-
this.getCandidateStickyLinesIntersectingFromOutline(range, this.outlineModel as StickyOutlineElement, stickyLineCandidates, 0, -1);
119-
const hiddenRanges: Range[] | undefined = this.editor._getViewModel()?.getHiddenAreas();
118+
this.getCandidateStickyLinesIntersectingFromOutline(range, this._outlineModel as StickyOutlineElement, stickyLineCandidates, 0, -1);
119+
const hiddenRanges: Range[] | undefined = this._editor._getViewModel()?.getHiddenAreas();
120120
if (hiddenRanges) {
121121
for (const hiddenRange of hiddenRanges) {
122122
stickyLineCandidates = stickyLineCandidates.filter(stickyLine => !(stickyLine.startLineNumber >= hiddenRange.startLineNumber && stickyLine.endLineNumber <= hiddenRange.endLineNumber + 1));
@@ -127,7 +127,7 @@ export class StickyLineCandidateProvider extends Disposable {
127127

128128
override dispose(): void {
129129
super.dispose();
130-
this.sessionStore.dispose();
130+
this._sessionStore.dispose();
131131
}
132132
}
133133

0 commit comments

Comments
 (0)