@@ -12,6 +12,7 @@ import { EditorOption } from 'vs/editor/common/config/editorOptions';
12
12
import { RunOnceScheduler } from 'vs/base/common/async' ;
13
13
import { Range } from 'vs/editor/common/core/range' ;
14
14
import { Emitter } from 'vs/base/common/event' ;
15
+ import { binarySearch } from 'vs/base/common/arrays' ;
15
16
16
17
export class StickyRange {
17
18
constructor (
@@ -96,8 +97,48 @@ export class StickyLineCandidateProvider extends Disposable {
96
97
}
97
98
}
98
99
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
+ }
99
108
public getCandidateStickyLinesIntersectingFromOutline ( range : StickyRange , outlineModel : StickyOutlineElement , result : StickyLineCandidate [ ] , depth : number , lastStartLineNumber : number ) : void {
100
109
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
+ /*
101
142
for (const child of outlineModel.children) {
102
143
if (child.range) {
103
144
const childStartLine = child.range.startLineNumber;
@@ -111,11 +152,15 @@ export class StickyLineCandidateProvider extends Disposable {
111
152
this.getCandidateStickyLinesIntersectingFromOutline(range, child, result, depth, lastStartLineNumber);
112
153
}
113
154
}
155
+ */
114
156
}
115
157
116
158
public getCandidateStickyLinesIntersecting ( range : StickyRange ) : StickyLineCandidate [ ] {
117
159
let stickyLineCandidates : StickyLineCandidate [ ] = [ ] ;
160
+ console . log ( 'this._outlineModel : ' , this . _outlineModel ) ;
161
+ console . log ( 'range : ' , range ) ;
118
162
this . getCandidateStickyLinesIntersectingFromOutline ( range , this . _outlineModel as StickyOutlineElement , stickyLineCandidates , 0 , - 1 ) ;
163
+ console . log ( 'stickyLineCandidates : ' , stickyLineCandidates ) ;
119
164
const hiddenRanges : Range [ ] | undefined = this . _editor . _getViewModel ( ) ?. getHiddenAreas ( ) ;
120
165
if ( hiddenRanges ) {
121
166
for ( const hiddenRange of hiddenRanges ) {
0 commit comments