diff --git a/lib/minimap-find-and-replace-binding.js b/lib/minimap-find-and-replace-binding.js index 57c834c..c426a9a 100644 --- a/lib/minimap-find-and-replace-binding.js +++ b/lib/minimap-find-and-replace-binding.js @@ -9,8 +9,8 @@ class MinimapFindAndReplaceBinding { this.fnrVisible = fnrVisible this.editor = this.minimap.getTextEditor() this.subscriptions = new CompositeDisposable() - this.decorationsByMarkerId = {} - this.subscriptionsByMarkerId = {} + this.decorationsByMarkerId = new Map() + this.subscriptionsByMarkerId = new Map() this.layer = this.fnrAPI.resultsMarkerLayerForTextEditor(this.editor) @@ -23,20 +23,22 @@ class MinimapFindAndReplaceBinding { this.discoverMarkers() } - destroy () { - let id - for (id in this.subscriptionsByMarkerId) { - const sub = this.subscriptionsByMarkerId[id]; sub.dispose() + disposeMarkerSubsctiotions () { + const markerSubscriptions = this.subscriptionsByMarkerId.values() + for (const markerSubscription of markerSubscriptions) { + markerSubscription.dispose() } - for (id in this.decorationsByMarkerId) { - const decoration = this.decorationsByMarkerId[id]; decoration.destroy() + const decorationSubscriotions = this.decorationsByMarkerId.values() + for (const decorationSubscriotion of decorationSubscriotions) { + decorationSubscriotion.destroy() } + } + destroy () { this.subscriptions.dispose() + this.clear() this.minimap = null this.editor = null - this.decorationsByMarkerId = {} - this.subscriptionsByMarkerId = {} } changeVisible (visible) { @@ -49,23 +51,15 @@ class MinimapFindAndReplaceBinding { } clear () { - let id - for (id in this.subscriptionsByMarkerId) { - const sub = this.subscriptionsByMarkerId[id] - sub.dispose() - delete this.subscriptionsByMarkerId[id] - } - - for (id in this.decorationsByMarkerId) { - const decoration = this.decorationsByMarkerId[id] - decoration.destroy() - delete this.decorationsByMarkerId[id] - } + this.disposeMarkerSubsctiotions() + this.decorationsByMarkerId.clear() + this.subscriptionsByMarkerId.clear() } discoverMarkers () { setImmediate(() => { - for (const marker of this.layer.getMarkers()) { + const markers = this.layer.getMarkers() + for (const marker of markers) { this.createDecoration(marker) } }) @@ -75,7 +69,7 @@ class MinimapFindAndReplaceBinding { if (!this.findViewIsVisible()) { return } - if (this.decorationsByMarkerId[marker.id]) { + if (this.decorationsByMarkerId.has(marker.id)) { return } @@ -89,15 +83,14 @@ class MinimapFindAndReplaceBinding { return } - const { - id, - } = marker - this.decorationsByMarkerId[id] = decoration - this.subscriptionsByMarkerId[id] = decoration.onDidDestroy(() => { - this.subscriptionsByMarkerId[id].dispose() - delete this.decorationsByMarkerId[id] - delete this.subscriptionsByMarkerId[id] - }) + const { id } = marker + this.decorationsByMarkerId.set(id, decoration) + this.subscriptionsByMarkerId.set(id, + decoration.onDidDestroy(() => { + this.subscriptionsByMarkerId.get(id).dispose() + this.subscriptionsByMarkerId.delete(id) + }), + ) } findViewIsVisible () { diff --git a/lib/minimap-find-and-replace.js b/lib/minimap-find-and-replace.js index ec5d962..f8670d2 100644 --- a/lib/minimap-find-and-replace.js +++ b/lib/minimap-find-and-replace.js @@ -8,11 +8,11 @@ module.exports = { return this.active }, - activate (state) { + activate () { this.active = false this.fnrVisible = false - this.bindingsById = {} - this.subscriptionsById = {} + this.bindingsById = new Map() + this.subscriptionsById = new Map() this.subscriptions = new CompositeDisposable() require('atom-package-deps').install('minimap-find-and-replace') }, @@ -46,23 +46,23 @@ module.exports = { MinimapFindAndReplaceBinding = require('./minimap-find-and-replace-binding') } - const { - id, - } = minimap + const { id } = minimap const binding = new MinimapFindAndReplaceBinding(minimap, fnr, this.fnrVisible) - this.bindingsById[id] = binding - - this.subscriptionsById[id] = minimap.onDidDestroy(() => { - if (this.subscriptionsById[id]) { - this.subscriptionsById[id].dispose() - } - if (this.bindingsById[id]) { - this.bindingsById[id].destroy() - } - - delete this.bindingsById[id] - delete this.subscriptionsById[id] - }) + this.bindingsById.set(id, binding) + + this.subscriptionsById.set(id, + minimap.onDidDestroy(() => { + if (this.subscriptionsById.has(id)) { + this.subscriptionsById.get(id).dispose() + } + if (this.bindingsById.has(id)) { + this.bindingsById.get(id).destroy() + } + + this.bindingsById.delete(id) + this.subscriptionsById.delete(id) + }), + ) })) }) }, @@ -87,13 +87,13 @@ module.exports = { changeVisible (visible) { this.fnrVisible = visible - for (const id in this.bindingsById) { - this.bindingsById[id].changeVisible(visible) + const bindings = this.bindingsById.values() + for (const binding of bindings) { + binding.changeVisible(visible) } }, deactivatePlugin () { - let id if (!this.active) { return } @@ -101,11 +101,14 @@ module.exports = { this.active = false this.subscriptions.dispose() - for (id in this.subscriptionsById) { - const sub = this.subscriptionsById[id]; sub.dispose() + const subscriptions = this.subscriptionsById.values() + for (const subscription of subscriptions) { + subscription.dispose() } - for (id in this.bindingsById) { - const binding = this.bindingsById[id]; binding.destroy() + + const bindings = this.bindingsById.values() + for (const binding of bindings) { + binding.destroy() } this.bindingsById = {} diff --git a/styles/minimap-find-and-replace.less b/styles/minimap-find-and-replace.less index 2f7f62b..dd81010 100644 --- a/styles/minimap-find-and-replace.less +++ b/styles/minimap-find-and-replace.less @@ -6,5 +6,6 @@ @import "syntax-variables"; .minimap .search-result { + contain: layout size paint style; background: @syntax-result-marker-color-selected; }