Skip to content
59 changes: 26 additions & 33 deletions lib/minimap-find-and-replace-binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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) {
Expand All @@ -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)
}
})
Expand All @@ -75,7 +69,7 @@ class MinimapFindAndReplaceBinding {
if (!this.findViewIsVisible()) {
return
}
if (this.decorationsByMarkerId[marker.id]) {
if (this.decorationsByMarkerId.has(marker.id)) {
return
}

Expand All @@ -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 () {
Expand Down
55 changes: 29 additions & 26 deletions lib/minimap-find-and-replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
},
Expand Down Expand Up @@ -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)
}),
)
}))
})
},
Expand All @@ -87,25 +87,28 @@ 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
}

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 = {}
Expand Down
1 change: 1 addition & 0 deletions styles/minimap-find-and-replace.less
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
@import "syntax-variables";

.minimap .search-result {
contain: layout size paint style;
background: @syntax-result-marker-color-selected;
}