Skip to content

Commit 0a532a4

Browse files
author
aiday-mar
committed
work in progress
1 parent d5a5929 commit 0a532a4

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { EditorOption } from 'vs/editor/common/config/editorOptions';
1212
import { RunOnceScheduler } from 'vs/base/common/async';
1313
import { Range } from 'vs/editor/common/core/range';
1414
import { Emitter } from 'vs/base/common/event';
15+
import { binarySearch } from 'vs/base/common/arrays';
1516

1617
export class StickyRange {
1718
constructor(
@@ -96,8 +97,48 @@ export class StickyLineCandidateProvider extends Disposable {
9697
}
9798
}
9899

100+
private changeIndex(index: number) {
101+
if (index === -1) {
102+
index = 0;
103+
} else if (index < 0) {
104+
index = -index - 2;
105+
}
106+
return index;
107+
}
99108
public getCandidateStickyLinesIntersectingFromOutline(range: StickyRange, outlineModel: StickyOutlineElement, result: StickyLineCandidate[], depth: number, lastStartLineNumber: number): void {
100109
let lastLine = lastStartLineNumber;
110+
// Find largest number in the start lines being smaller than the current range start line
111+
const childrenStartLines = outlineModel.children.map(child => child.range?.startLineNumber as number);
112+
let indexLower = binarySearch(childrenStartLines, range.startLineNumber, (a: number, b: number) => { return a - b; });
113+
let indexUpper = binarySearch(childrenStartLines, range.startLineNumber + depth, (a: number, b: number) => { return a - b; });
114+
console.log('children start lines : ', childrenStartLines);
115+
console.log('range start line number : ', range.startLineNumber);
116+
console.log('range.startLineNumber + depth : ', range.startLineNumber + depth);
117+
console.log('index lower before change : ', indexLower);
118+
console.log('index upper before change : ', indexUpper);
119+
120+
indexLower = this.changeIndex(indexLower);
121+
indexUpper = this.changeIndex(indexUpper);
122+
123+
console.log('indexLower : ', indexLower);
124+
console.log('indexUpper : ', indexUpper);
125+
126+
for (let i = indexLower; i <= indexUpper; i++) {
127+
console.log('currently at index : ', i);
128+
const child = outlineModel.children[i];
129+
if (child && child.range) {
130+
const childStartLine = child.range.startLineNumber;
131+
const childEndLine = child.range.endLineNumber;
132+
if (range.startLineNumber <= childEndLine + 1 && childStartLine - 1 <= range.endLineNumber && childStartLine !== lastLine) {
133+
lastLine = childStartLine;
134+
result.push(new StickyLineCandidate(childStartLine, childEndLine - 1, depth + 1));
135+
this.getCandidateStickyLinesIntersectingFromOutline(range, child, result, depth + 1, childStartLine);
136+
}
137+
} else {
138+
this.getCandidateStickyLinesIntersectingFromOutline(range, child, result, depth, lastStartLineNumber);
139+
}
140+
}
141+
/*
101142
for (const child of outlineModel.children) {
102143
if (child.range) {
103144
const childStartLine = child.range.startLineNumber;
@@ -111,11 +152,15 @@ export class StickyLineCandidateProvider extends Disposable {
111152
this.getCandidateStickyLinesIntersectingFromOutline(range, child, result, depth, lastStartLineNumber);
112153
}
113154
}
155+
*/
114156
}
115157

116158
public getCandidateStickyLinesIntersecting(range: StickyRange): StickyLineCandidate[] {
117159
let stickyLineCandidates: StickyLineCandidate[] = [];
160+
console.log('this._outlineModel : ', this._outlineModel);
161+
console.log('range : ', range);
118162
this.getCandidateStickyLinesIntersectingFromOutline(range, this._outlineModel as StickyOutlineElement, stickyLineCandidates, 0, -1);
163+
console.log('stickyLineCandidates : ', stickyLineCandidates);
119164
const hiddenRanges: Range[] | undefined = this._editor._getViewModel()?.getHiddenAreas();
120165
if (hiddenRanges) {
121166
for (const hiddenRange of hiddenRanges) {

0 commit comments

Comments
 (0)