Skip to content

Commit 78f4023

Browse files
author
Aiday Marlen Kyzy
authored
Merge pull request microsoft#156578 from aiday-mar/aiday/semanticScroll
Filtering the ranges with the hidden ranges from folding. Fixes microsoft#156268.
2 parents e45b7a5 + bd9ff90 commit 78f4023

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { LineDecoration } from 'vs/editor/common/viewLayout/lineDecorations';
1919
import { RunOnceScheduler } from 'vs/base/common/async';
2020
import { IModelTokensChangedEvent } from 'vs/editor/common/textModelEvents';
2121
import { Position } from 'vs/editor/common/core/position';
22+
import { Range } from 'vs/editor/common/core/range';
2223

2324
class StickyScrollController extends Disposable implements IEditorContribution {
2425

@@ -61,6 +62,7 @@ class StickyScrollController extends Disposable implements IEditorContribution {
6162
this._editor.addOverlayWidget(this.stickyScrollWidget);
6263
this._sessionStore.add(this._editor.onDidChangeModel(() => this._update(true)));
6364
this._sessionStore.add(this._editor.onDidScrollChange(() => this._update(false)));
65+
this._sessionStore.add(this._editor.onDidChangeHiddenAreas(() => this._update(true)));
6466
this._sessionStore.add(this._editor.onDidChangeModelTokens((e) => this._onTokensChange(e)));
6567
this._sessionStore.add(this._editor.onDidChangeModelContent(() => this._updateSoon.schedule()));
6668
this._sessionStore.add(this._languageFeaturesService.documentSymbolProvider.onDidChange(() => this._update(true)));
@@ -92,6 +94,12 @@ class StickyScrollController extends Disposable implements IEditorContribution {
9294
this._cts = new CancellationTokenSource();
9395
await this._updateOutlineModel(this._cts.token);
9496
}
97+
const hiddenRanges: Range[] | undefined = this._editor._getViewModel()?.getHiddenAreas();
98+
if (hiddenRanges) {
99+
for (const hiddenRange of hiddenRanges) {
100+
this._ranges = this._ranges.filter(range => { return !(range[0] >= hiddenRange.startLineNumber && range[1] <= hiddenRange.endLineNumber + 1); });
101+
}
102+
}
95103
this._renderStickyScroll();
96104
}
97105

@@ -202,12 +210,12 @@ class StickyScrollController extends Disposable implements IEditorContribution {
202210
if (!beginningLinesConsidered.has(start)) {
203211
if (topOfElementAtDepth >= topOfEndLine - 1 && topOfElementAtDepth < bottomOfEndLine - 2) {
204212
beginningLinesConsidered.add(start);
205-
this.stickyScrollWidget.pushCodeLine(new StickyScrollCodeLine(start, this._editor, -1, bottomOfEndLine - bottomOfElementAtDepth));
213+
this.stickyScrollWidget.pushCodeLine(new StickyScrollCodeLine(start, depth, this._editor, -1, bottomOfEndLine - bottomOfElementAtDepth));
206214
break;
207215
}
208-
else if (bottomOfElementAtDepth > bottomOfBeginningLine - 1 && bottomOfElementAtDepth < bottomOfEndLine - 1) {
216+
else if (bottomOfElementAtDepth > bottomOfBeginningLine && bottomOfElementAtDepth < bottomOfEndLine - 1) {
209217
beginningLinesConsidered.add(start);
210-
this.stickyScrollWidget.pushCodeLine(new StickyScrollCodeLine(start, this._editor, 0, 0));
218+
this.stickyScrollWidget.pushCodeLine(new StickyScrollCodeLine(start, depth, this._editor, 0, 0));
211219
}
212220
} else {
213221
this._ranges.splice(index, 1);
@@ -229,7 +237,7 @@ class StickyScrollCodeLine {
229237

230238
public readonly effectiveLineHeight: number = 0;
231239

232-
constructor(private readonly _lineNumber: number, private readonly _editor: IActiveCodeEditor,
240+
constructor(private readonly _lineNumber: number, private readonly _depth: number, private readonly _editor: IActiveCodeEditor,
233241
private readonly _zIndex: number, private readonly _relativePosition: number) {
234242
this.effectiveLineHeight = this._editor.getOption(EditorOption.lineHeight) + this._relativePosition;
235243
}
@@ -294,8 +302,9 @@ class StickyScrollCodeLine {
294302
root.onclick = e => {
295303
e.stopPropagation();
296304
e.preventDefault();
297-
this._editor.revealLine(this._lineNumber);
305+
this._editor.revealPosition({ lineNumber: this._lineNumber - this._depth + 1, column: 1 });
298306
};
307+
299308
root.onmouseover = e => {
300309
innerLineNumberHTML.style.background = `var(--vscode-editorStickyScrollHover-background)`;
301310
lineHTMLNode.style.backgroundColor = `var(--vscode-editorStickyScrollHover-background)`;
@@ -345,7 +354,7 @@ class StickyScrollWidget implements IOverlayWidget {
345354
constructor(public readonly _editor: ICodeEditor) {
346355
this.rootDomNode = document.createElement('div');
347356
this.rootDomNode.style.width = '100%';
348-
this.rootDomNode.style.boxShadow = `var(--vscode-scrollbar-shadow) 0 6px 6px -6px`; // '0px 0px 8px 2px #000000';
357+
this.rootDomNode.style.boxShadow = `var(--vscode-scrollbar-shadow) 0 6px 6px -6px`;
349358
}
350359

351360
get codeLineCount() {

0 commit comments

Comments
 (0)