@@ -188,6 +188,14 @@ export class StickyLineCandidateProvider extends Disposable {
188188
189189class StickyOutlineElement {
190190
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+
191199 public static fromOutlineElement ( outlineElement : OutlineElement , previousStartLine : number ) : StickyOutlineElement {
192200 const children : StickyOutlineElement [ ] = [ ] ;
193201 for ( const child of outlineElement . children . values ( ) ) {
@@ -201,15 +209,7 @@ class StickyOutlineElement {
201209 }
202210 }
203211 }
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 ! ) ) ;
213213 const range = new StickyRange ( outlineElement . symbol . selectionRange . startLineNumber , outlineElement . symbol . range . endLineNumber ) ;
214214 return new StickyOutlineElement ( range , children , undefined ) ;
215215 }
@@ -242,7 +242,12 @@ class StickyOutlineElement {
242242 outlineElements = outlineModel . children as Map < string , OutlineElement > ;
243243 }
244244 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 ) {
246251 stickyChildren . push ( StickyOutlineElement . fromOutlineElement ( outlineElement , outlineElement . symbol . selectionRange . startLineNumber ) ) ;
247252 }
248253 const stickyOutlineElement = new StickyOutlineElement ( undefined , stickyChildren , undefined ) ;
@@ -279,7 +284,7 @@ class StickyOutlineElement {
279284 let parentStickyOutlineElement = stickyOutlineElement ;
280285
281286 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 ) ;
283288 while ( stackOfParents . length !== 0 && ( range . startLineNumber < stackOfParents [ stackOfParents . length - 1 ] . startLineNumber || range . endLineNumber > stackOfParents [ stackOfParents . length - 1 ] . endLineNumber ) ) {
284289 stackOfParents . pop ( ) ;
285290 if ( parentStickyOutlineElement . parent !== undefined ) {
0 commit comments