Skip to content

Commit

Permalink
🐛 Fix errors raised when destroying the minimap
Browse files Browse the repository at this point in the history
Fixes #4
  • Loading branch information
abe33 committed Feb 10, 2015
1 parent 3b9b679 commit c65692b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
7 changes: 6 additions & 1 deletion lib/minimap-selection.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ module.exports =
minimap = o.view ? o
selectionView = new MinimapSelectionView(minimap)

@views[minimap.getTextEditor().id] = selectionView
@views[minimap.id] = selectionView

disposable = minimap.onDidDestroy =>
selectionView.destroy()
delete @views[minimap.id]
disposable.dispose()

deactivatePlugin: ->
return unless @active
Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/sample.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

module.exports =
class Dummy
constructor: (@name) ->
35 changes: 28 additions & 7 deletions spec/minimap-selection-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{WorkspaceView} = require 'atom'
MinimapSelection = require '../lib/minimap-selection'

# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
Expand All @@ -7,12 +6,34 @@ MinimapSelection = require '../lib/minimap-selection'
# or `fdescribe`). Remove the `f` to unfocus the block.

describe "MinimapSelection", ->
activationPromise = null
[workspaceElement, editor, minimap, minimapModule] = []

beforeEach ->
atom.workspaceView = new WorkspaceView
activationPromise = atom.packages.activatePackage('minimap-selection')
workspaceElement = atom.views.getView(atom.workspace)

describe "when the minimap-selection:toggle event is triggered", ->
it "attaches and then detaches the view", ->
waitsForPromise -> activationPromise
waitsForPromise -> atom.workspace.open('sample.coffee')
waitsForPromise -> atom.packages.activatePackage('minimap').then (pkg) ->
minimapModule = pkg.mainModule

waitsForPromise -> atom.packages.activatePackage('minimap-selection')

runs ->
editor = atom.workspace.getActiveTextEditor()
minimap = minimapModule.minimapForEditor(editor)

spyOn(minimap, 'decorateMarker').andCallThrough()
spyOn(minimap, 'removeDecoration').andCallThrough()

describe 'when a selection is made in the text editor', ->
beforeEach ->
editor.setSelectedBufferRange([[1,0], [2,10]])

it 'adds a decoration for the selection in the minimap', ->
expect(minimap.decorateMarker).toHaveBeenCalled()

describe 'and then removed', ->
beforeEach ->
editor.setSelectedBufferRange([[0,0], [0,0]])

it 'removes the previously added decoration', ->
expect(minimap.removeDecoration).toHaveBeenCalled()
File renamed without changes.

0 comments on commit c65692b

Please sign in to comment.