@@ -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,9 +97,34 @@ export class StickyLineCandidateProvider extends Disposable {
96
97
}
97
98
}
98
99
100
+ private updateIndex ( index : number ) {
101
+ if ( index === - 1 ) {
102
+ index = 0 ;
103
+ } else if ( index < 0 ) {
104
+ index = - index - 2 ;
105
+ }
106
+ return index ;
107
+ }
108
+
99
109
public getCandidateStickyLinesIntersectingFromOutline ( range : StickyRange , outlineModel : StickyOutlineElement , result : StickyLineCandidate [ ] , depth : number , lastStartLineNumber : number ) : void {
110
+ if ( outlineModel . children . length === 0 ) {
111
+ return ;
112
+ }
100
113
let lastLine = lastStartLineNumber ;
101
- for ( const child of outlineModel . children ) {
114
+ const childrenStartLines : number [ ] = [ ] ;
115
+ for ( let i = 0 ; i < outlineModel . children . length ; i ++ ) {
116
+ const child = outlineModel . children [ i ] ;
117
+ if ( child . range ) {
118
+ childrenStartLines . push ( child . range . startLineNumber ) ;
119
+ }
120
+ }
121
+ const lowerBound = this . updateIndex ( binarySearch ( childrenStartLines , range . startLineNumber , ( a : number , b : number ) => { return a - b ; } ) ) ;
122
+ const upperBound = this . updateIndex ( binarySearch ( childrenStartLines , range . startLineNumber + depth , ( a : number , b : number ) => { return a - b ; } ) ) ;
123
+ for ( let i = lowerBound ; i <= upperBound ; i ++ ) {
124
+ const child = outlineModel . children [ i ] ;
125
+ if ( ! child ) {
126
+ return ;
127
+ }
102
128
if ( child . range ) {
103
129
const childStartLine = child . range . startLineNumber ;
104
130
const childEndLine = child . range . endLineNumber ;
@@ -133,9 +159,13 @@ export class StickyLineCandidateProvider extends Disposable {
133
159
134
160
class StickyOutlineElement {
135
161
public static fromOutlineModel ( outlineModel : OutlineModel | OutlineElement | OutlineGroup ) : StickyOutlineElement {
136
- const children = [ ...outlineModel . children . values ( ) ] . map ( child =>
137
- StickyOutlineElement . fromOutlineModel ( child )
138
- ) ;
162
+
163
+ const children : StickyOutlineElement [ ] = [ ] ;
164
+ for ( const child of outlineModel . children . values ( ) ) {
165
+ if ( child instanceof OutlineElement && child . symbol . selectionRange . startLineNumber !== child . symbol . range . endLineNumber || child instanceof OutlineGroup || child instanceof OutlineModel ) {
166
+ children . push ( StickyOutlineElement . fromOutlineModel ( child ) ) ;
167
+ }
168
+ }
139
169
children . sort ( ( child1 , child2 ) => {
140
170
if ( ! child1 . range || ! child2 . range ) {
141
171
return 1 ;
0 commit comments