Skip to content

Commit e595d70

Browse files
authored
Merge pull request #765 from atom-minimap/toggle-null-bugs
2 parents 97cada6 + a5ac5ec commit e595d70

File tree

5 files changed

+189
-150
lines changed

5 files changed

+189
-150
lines changed

lib/decoration-management.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,13 @@ export default class DecorationManagement {
603603
this.decorationUpdatedSubscriptions.clear()
604604
this.decorationDestroyedSubscriptions.clear()
605605
}
606+
607+
destroy () {
608+
this.removeAllDecorations()
609+
this.minimap = undefined
610+
this.emitter = undefined
611+
this.destroyed = true
612+
}
606613
}
607614

608615
function getOriginatorPackageName () {

lib/main.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ let toggled = false
4040
* @type {Map}
4141
* @access private
4242
*/
43-
let editorsMinimaps = null
43+
export let editorsMinimaps = null
4444
/**
4545
* The composite disposable that stores the package's subscriptions.
4646
*
@@ -122,10 +122,10 @@ export function deactivate () {
122122
PluginManagement.deactivateAllPlugins()
123123

124124
if (editorsMinimaps) {
125-
editorsMinimaps.forEach((value, key) => {
125+
editorsMinimaps.forEach((value) => {
126126
value.destroy()
127-
editorsMinimaps.delete(key)
128127
})
128+
editorsMinimaps.clear()
129129
}
130130

131131
subscriptions.dispose()
@@ -152,12 +152,21 @@ export function toggle () {
152152
toggled = false
153153

154154
if (editorsMinimaps) {
155-
editorsMinimaps.forEach((value, key) => {
156-
value.destroy()
157-
editorsMinimaps.delete(key)
155+
editorsMinimaps.forEach((minimap) => {
156+
minimap.destroy()
158157
})
158+
editorsMinimaps.clear()
159159
}
160160
subscriptions.dispose()
161+
162+
// HACK: this hack forces rerendering editor size which moves the scrollbar to the right once minimap is removed
163+
const wasMaximized = atom.isMaximized()
164+
const { width, height } = atom.getSize()
165+
atom.setSize(width, height)
166+
if (wasMaximized) {
167+
atom.maximize()
168+
}
169+
161170
} else {
162171
toggled = true
163172
initSubscriptions()
@@ -298,13 +307,12 @@ export function minimapForEditor (textEditor) {
298307

299308
let minimap = editorsMinimaps.get(textEditor)
300309

301-
if (!minimap) {
310+
if (minimap === undefined || minimap.destroyed) {
302311
minimap = new Minimap({ textEditor })
303312
editorsMinimaps.set(textEditor, minimap)
304313

305314
const editorSubscription = textEditor.onDidDestroy(() => {
306-
const minimaps = editorsMinimaps
307-
if (minimaps) { minimaps.delete(textEditor) }
315+
if (editorsMinimaps) { editorsMinimaps.delete(textEditor) }
308316
editorSubscription.dispose()
309317
})
310318
}
@@ -363,10 +371,10 @@ function initSubscriptions () {
363371
subscriptions.add(
364372
atom.workspace.observeTextEditors((textEditor) => {
365373
const minimap = minimapForEditor(textEditor)
366-
const minimapElement = atom.views.getView(minimap)
374+
const minimapElement = minimap.getMinimapElement() || minimapViewProvider(minimap)
367375

368376
emitter.emit('did-create-minimap', minimap)
369-
minimapElement.attach()
377+
minimapElement.attach(textEditor.getElement())
370378
}),
371379
// empty color cache if the theme changes
372380
atom.themes.onDidChangeActiveThemes(() => {

lib/minimap-element.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,10 @@ class MinimapElement {
427427
const container = parent || this.minimap.getTextEditorElement()
428428
const minimaps = container.querySelectorAll('atom-text-editor-minimap')
429429
if (minimaps.length) {
430-
Array.prototype.forEach.call(minimaps, (el) => { el.destroy() })
430+
Array.prototype.forEach.call(minimaps, (el) => {
431+
el.destroy()
432+
container.removeChild(el)
433+
})
431434
}
432435
container.appendChild(this)
433436
}
@@ -454,12 +457,16 @@ class MinimapElement {
454457
* Destroys this MinimapElement
455458
*/
456459
destroy () {
460+
this.DecorationManagement.destroy()
461+
if (this.quickSettingsElement) {
462+
this.quickSettingsElement.destroy()
463+
}
457464
this.subscriptions.dispose()
458-
this.DecorationManagement.removeAllDecorations()
459-
this.DecorationManagement.destroyed = true
460465
this.detach()
461-
this.minimap.minimapElement = null
462-
this.minimap = null
466+
if (this.minimap) {
467+
this.minimap.minimapElement = null
468+
this.minimap = null
469+
}
463470
}
464471

465472
// ###### ####### ## ## ######## ######## ## ## ########

lib/minimap-quick-settings-element.js

Lines changed: 94 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -44,111 +44,114 @@ class MinimapQuickSettingsElement {
4444
this.plugins = {}
4545
this.itemsActions = new WeakMap()
4646

47-
const subs = this.subscriptions
48-
49-
subs.add(Main.onDidAddPlugin(({ name, plugin }) => {
50-
return this.addItemFor(name, plugin)
51-
}))
52-
subs.add(Main.onDidRemovePlugin(({ name, plugin }) => {
53-
return this.removeItemFor(name, plugin)
54-
}))
55-
subs.add(Main.onDidActivatePlugin(({ name, plugin }) => {
56-
return this.activateItem(name, plugin)
57-
}))
58-
subs.add(Main.onDidDeactivatePlugin(({ name, plugin }) => {
59-
return this.deactivateItem(name, plugin)
60-
}))
61-
62-
subs.add(atom.commands.add('minimap-quick-settings', {
63-
'core:move-up': () => {
64-
this.selectPreviousItem()
65-
},
66-
'core:move-down': () => {
67-
this.selectNextItem()
68-
},
69-
'core:move-left': () => {
70-
atom.config.set('minimap.displayMinimapOnLeft', true)
71-
},
72-
'core:move-right': () => {
73-
atom.config.set('minimap.displayMinimapOnLeft', false)
74-
},
75-
'core:cancel': () => {
76-
this.destroy()
77-
},
78-
'core:confirm': () => {
79-
this.toggleSelectedItem()
80-
}
81-
}))
82-
8347
this.codeHighlights.classList.toggle('active', this.minimap.displayCodeHighlights)
8448

85-
subs.add(this.subscribeTo(this.codeHighlights, {
86-
mousedown: (e) => {
87-
e.preventDefault()
88-
atom.config.set('minimap.displayCodeHighlights', !this.minimap.displayCodeHighlights)
89-
}
90-
}))
91-
9249
this.itemsActions.set(this.codeHighlights, () => {
9350
atom.config.set('minimap.displayCodeHighlights', !this.minimap.displayCodeHighlights)
9451
})
9552

96-
subs.add(this.subscribeTo(this.absoluteMode, {
97-
mousedown: (e) => {
98-
e.preventDefault()
99-
atom.config.set('minimap.absoluteMode', !atom.config.get('minimap.absoluteMode'))
100-
}
101-
}))
102-
10353
this.itemsActions.set(this.absoluteMode, () => {
10454
atom.config.set('minimap.absoluteMode', !atom.config.get('minimap.absoluteMode'))
10555
})
10656

107-
subs.add(this.subscribeTo(this.adjustAbsoluteModeHeight, {
108-
mousedown: (e) => {
109-
e.preventDefault()
110-
atom.config.set('minimap.adjustAbsoluteModeHeight', !atom.config.get('minimap.adjustAbsoluteModeHeight'))
111-
}
112-
}))
113-
11457
this.itemsActions.set(this.adjustAbsoluteModeHeight, () => {
11558
atom.config.set('minimap.adjustAbsoluteModeHeight', !atom.config.get('minimap.adjustAbsoluteModeHeight'))
11659
})
11760

118-
subs.add(this.subscribeTo(this.hiddenInput, {
119-
focusout: (e) => { this.destroy() }
120-
}, { passive: true }))
121-
122-
subs.add(this.subscribeTo(this.onLeftButton, {
123-
mousedown: (e) => {
124-
e.preventDefault()
125-
atom.config.set('minimap.displayMinimapOnLeft', true)
126-
}
127-
}))
128-
129-
subs.add(this.subscribeTo(this.onRightButton, {
130-
mousedown: (e) => {
131-
e.preventDefault()
132-
atom.config.set('minimap.displayMinimapOnLeft', false)
133-
}
134-
}))
135-
136-
subs.add(atom.config.observe('minimap.displayCodeHighlights', (bool) => {
137-
this.codeHighlights.classList.toggle('active', bool)
138-
}))
139-
140-
subs.add(atom.config.observe('minimap.absoluteMode', (bool) => {
141-
this.absoluteMode.classList.toggle('active', bool)
142-
}))
143-
144-
subs.add(atom.config.observe('minimap.adjustAbsoluteModeHeight', (bool) => {
145-
this.adjustAbsoluteModeHeight.classList.toggle('active', bool)
146-
}))
147-
148-
subs.add(atom.config.observe('minimap.displayMinimapOnLeft', (bool) => {
149-
this.onLeftButton.classList.toggle('selected', bool)
150-
this.onRightButton.classList.toggle('selected', !bool)
151-
}))
61+
this.subscriptions.add(
62+
63+
Main.onDidAddPlugin(({ name, plugin }) => {
64+
return this.addItemFor(name, plugin)
65+
}),
66+
Main.onDidRemovePlugin(({ name, plugin }) => {
67+
return this.removeItemFor(name, plugin)
68+
}),
69+
Main.onDidActivatePlugin(({ name, plugin }) => {
70+
return this.activateItem(name, plugin)
71+
}),
72+
Main.onDidDeactivatePlugin(({ name, plugin }) => {
73+
return this.deactivateItem(name, plugin)
74+
}),
75+
76+
atom.commands.add('minimap-quick-settings', {
77+
'core:move-up': () => {
78+
this.selectPreviousItem()
79+
},
80+
'core:move-down': () => {
81+
this.selectNextItem()
82+
},
83+
'core:move-left': () => {
84+
atom.config.set('minimap.displayMinimapOnLeft', true)
85+
},
86+
'core:move-right': () => {
87+
atom.config.set('minimap.displayMinimapOnLeft', false)
88+
},
89+
'core:cancel': () => {
90+
this.destroy()
91+
},
92+
'core:confirm': () => {
93+
this.toggleSelectedItem()
94+
}
95+
}),
96+
97+
this.subscribeTo(this.codeHighlights, {
98+
mousedown: (e) => {
99+
e.preventDefault()
100+
atom.config.set('minimap.displayCodeHighlights', !this.minimap.displayCodeHighlights)
101+
}
102+
}),
103+
104+
this.subscribeTo(this.absoluteMode, {
105+
mousedown: (e) => {
106+
e.preventDefault()
107+
atom.config.set('minimap.absoluteMode', !atom.config.get('minimap.absoluteMode'))
108+
}
109+
}),
110+
111+
this.subscribeTo(this.adjustAbsoluteModeHeight, {
112+
mousedown: (e) => {
113+
e.preventDefault()
114+
atom.config.set('minimap.adjustAbsoluteModeHeight', !atom.config.get('minimap.adjustAbsoluteModeHeight'))
115+
}
116+
}),
117+
118+
this.subscribeTo(this.hiddenInput, {
119+
focusout: (e) => { this.destroy() }
120+
},
121+
{ passive: true }
122+
),
123+
124+
this.subscribeTo(this.onLeftButton, {
125+
mousedown: (e) => {
126+
e.preventDefault()
127+
atom.config.set('minimap.displayMinimapOnLeft', true)
128+
}
129+
}),
130+
131+
this.subscribeTo(this.onRightButton, {
132+
mousedown: (e) => {
133+
e.preventDefault()
134+
atom.config.set('minimap.displayMinimapOnLeft', false)
135+
}
136+
}),
137+
138+
atom.config.observe('minimap.displayCodeHighlights', (bool) => {
139+
this.codeHighlights.classList.toggle('active', bool)
140+
}),
141+
142+
atom.config.observe('minimap.absoluteMode', (bool) => {
143+
this.absoluteMode.classList.toggle('active', bool)
144+
}),
145+
146+
atom.config.observe('minimap.adjustAbsoluteModeHeight', (bool) => {
147+
this.adjustAbsoluteModeHeight.classList.toggle('active', bool)
148+
}),
149+
150+
atom.config.observe('minimap.displayMinimapOnLeft', (bool) => {
151+
this.onLeftButton.classList.toggle('selected', bool)
152+
this.onRightButton.classList.toggle('selected', !bool)
153+
})
154+
)
152155

153156
this.initList()
154157
}

0 commit comments

Comments
 (0)