@@ -188,6 +188,14 @@ export class StickyLineCandidateProvider extends Disposable {
188
188
189
189
class StickyOutlineElement {
190
190
191
+ private static comparator ( range1 : StickyRange , range2 : StickyRange ) : number {
192
+ if ( range1 . startLineNumber !== range2 . startLineNumber ) {
193
+ return range1 . startLineNumber - range2 . startLineNumber ;
194
+ } else {
195
+ return range2 . endLineNumber - range1 . endLineNumber ;
196
+ }
197
+ }
198
+
191
199
public static fromOutlineElement ( outlineElement : OutlineElement , previousStartLine : number ) : StickyOutlineElement {
192
200
const children : StickyOutlineElement [ ] = [ ] ;
193
201
for ( const child of outlineElement . children . values ( ) ) {
@@ -201,15 +209,7 @@ class StickyOutlineElement {
201
209
}
202
210
}
203
211
}
204
- children . sort ( ( child1 , child2 ) => {
205
- if ( ! child1 . range || ! child2 . range ) {
206
- return 1 ;
207
- } else if ( child1 . range . startLineNumber !== child2 . range . startLineNumber ) {
208
- return child1 . range . startLineNumber - child2 . range . startLineNumber ;
209
- } else {
210
- return child2 . range . endLineNumber - child1 . range . endLineNumber ;
211
- }
212
- } ) ;
212
+ children . sort ( ( child1 , child2 ) => this . comparator ( child1 . range ! , child2 . range ! ) ) ;
213
213
const range = new StickyRange ( outlineElement . symbol . selectionRange . startLineNumber , outlineElement . symbol . range . endLineNumber ) ;
214
214
return new StickyOutlineElement ( range , children , undefined ) ;
215
215
}
@@ -242,7 +242,12 @@ class StickyOutlineElement {
242
242
outlineElements = outlineModel . children as Map < string , OutlineElement > ;
243
243
}
244
244
const stickyChildren : StickyOutlineElement [ ] = [ ] ;
245
- for ( const outlineElement of outlineElements . values ( ) ) {
245
+ const outlineElementsArray = Array . from ( outlineElements . values ( ) ) . sort ( ( element1 , element2 ) => {
246
+ const range1 : StickyRange = new StickyRange ( element1 . symbol . range . startLineNumber , element1 . symbol . range . endLineNumber ) ;
247
+ const range2 : StickyRange = new StickyRange ( element2 . symbol . range . startLineNumber , element2 . symbol . range . endLineNumber ) ;
248
+ return this . comparator ( range1 , range2 ) ;
249
+ } ) ;
250
+ for ( const outlineElement of outlineElementsArray ) {
246
251
stickyChildren . push ( StickyOutlineElement . fromOutlineElement ( outlineElement , outlineElement . symbol . selectionRange . startLineNumber ) ) ;
247
252
}
248
253
const stickyOutlineElement = new StickyOutlineElement ( undefined , stickyChildren , undefined ) ;
@@ -279,7 +284,7 @@ class StickyOutlineElement {
279
284
let parentStickyOutlineElement = stickyOutlineElement ;
280
285
281
286
for ( let i = 0 ; i < length ; i ++ ) {
282
- range = new StickyRange ( regions . getStartLineNumber ( i ) , regions . getEndLineNumber ( i ) ) ;
287
+ range = new StickyRange ( regions . getStartLineNumber ( i ) , regions . getEndLineNumber ( i ) + 1 ) ;
283
288
while ( stackOfParents . length !== 0 && ( range . startLineNumber < stackOfParents [ stackOfParents . length - 1 ] . startLineNumber || range . endLineNumber > stackOfParents [ stackOfParents . length - 1 ] . endLineNumber ) ) {
284
289
stackOfParents . pop ( ) ;
285
290
if ( parentStickyOutlineElement . parent !== undefined ) {
0 commit comments