@@ -6,11 +6,10 @@ export default class MinimapCursorLineBinding {
66 constructor ( minimap ) {
77 this . minimap = minimap
88 this . subscriptions = new CompositeDisposable ( )
9- this . editor = this . minimap . getTextEditor ( )
10- this . decorationsByMarkerId = { }
11- this . decorationSubscriptionsByMarkerId = { }
9+ this . decorationsByMarkerId = new Map ( )
10+ this . decorationSubscriptionsByMarkerId = new Map ( )
1211
13- this . subscriptions . add ( this . editor . observeCursors ( ( cursor ) => {
12+ this . subscriptions . add ( this . minimap . getTextEditor ( ) . observeCursors ( ( cursor ) => {
1413 this . handleMarker ( cursor . getMarker ( ) )
1514 } ) )
1615 }
@@ -20,24 +19,31 @@ export default class MinimapCursorLineBinding {
2019 const decoration = this . minimap . decorateMarker (
2120 marker , { type : 'line' , class : 'cursor-line' } ,
2221 )
23- this . decorationsByMarkerId [ id ] = decoration
24- this . decorationSubscriptionsByMarkerId [ id ] = decoration . onDidDestroy ( ( ) => {
25- this . decorationSubscriptionsByMarkerId [ id ] . dispose ( )
26-
27- delete this . decorationsByMarkerId [ id ]
28- delete this . decorationSubscriptionsByMarkerId [ id ]
29- } )
22+ this . decorationsByMarkerId . set ( id , decoration )
23+
24+ this . decorationSubscriptionsByMarkerId . set ( id ,
25+ decoration . onDidDestroy ( ( ) => {
26+ const cachedDecoration = this . decorationSubscriptionsByMarkerId . get ( id )
27+ if ( cachedDecoration ) {
28+ cachedDecoration . dispose ( )
29+ }
30+
31+ this . decorationsByMarkerId . delete ( id )
32+ this . decorationSubscriptionsByMarkerId . delete ( id )
33+ } ) ,
34+ )
3035 }
3136
3237 destroy ( ) {
33- for ( const id in this . decorationsByMarkerId ) {
34- const decoration = this . decorationsByMarkerId [ id ]
35- this . decorationSubscriptionsByMarkerId [ id ] . dispose ( )
38+ for ( const [ id , decoration ] of this . decorationsByMarkerId ) {
39+ const decorationSub = this . decorationSubscriptionsByMarkerId . get ( id )
40+ if ( decorationSub ) {
41+ decorationSub . dispose ( )
42+ }
3643 decoration . destroy ( )
37-
38- delete this . decorationsByMarkerId [ id ]
39- delete this . decorationSubscriptionsByMarkerId [ id ]
4044 }
45+ this . decorationsByMarkerId . clear ( )
46+ this . decorationSubscriptionsByMarkerId . clear ( )
4147
4248 this . subscriptions . dispose ( )
4349 }
0 commit comments