Skip to content

Commit 7770773

Browse files
authored
fix: decoration management fixes (#52)
1 parent a20d6bb commit 7770773

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

lib/minimap-cursorline-binding.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

lib/minimap-cursorline.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default {
1010

1111
isActive () { return this.active },
1212

13-
bindings: {},
13+
bindings: new Map(),
1414

1515
activate () {
1616
require('atom-package-deps').install('minimap-cursorline')
@@ -40,13 +40,13 @@ export default {
4040

4141
const id = minimap.id
4242
const binding = new MinimapCursorLineBinding(minimap)
43-
this.bindings[id] = binding
43+
this.bindings.set(id, binding)
4444

4545
const subscription = minimap.onDidDestroy(() => {
4646
binding.destroy()
4747
this.subscriptions.remove(subscription)
4848
subscription.dispose()
49-
delete this.bindings[id]
49+
this.bindings.delete(id)
5050
})
5151

5252
this.subscriptions.add(subscription)
@@ -56,8 +56,8 @@ export default {
5656
deactivatePlugin () {
5757
if (!this.active) { return }
5858

59-
for (const id in this.bindings) { this.bindings[id].destroy() }
60-
this.bindings = {}
59+
for (const binding of this.bindings.values()) { binding.destroy() }
60+
this.bindings.clear()
6161
this.active = false
6262
this.minimapsSubscription.dispose()
6363
this.subscriptions.dispose()

0 commit comments

Comments
 (0)