Skip to content

Commit

Permalink
Implement minimap model destruction
Browse files Browse the repository at this point in the history
  • Loading branch information
abe33 committed Dec 17, 2014
1 parent 720a948 commit b65698b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/minimap.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class Minimap extends Model
@emitter.emit('did-change-scroll-top', scrollTop)
subs.add @textEditor.onDidChangeScrollLeft (scrollLeft) =>
@emitter.emit('did-change-scroll-left', scrollLeft)
subs.add @textEditor.onDidDestroy => @destroy()

destroyed: ->
@subscriptions.dispose()
@textEditor = null
@emitter.emit 'did-destroy'

onDidChange: (callback) -> @emitter.on 'did-change', callback

Expand All @@ -38,6 +44,9 @@ class Minimap extends Model
onDidChangeScrollLeft: (callback) ->
@emitter.on 'did-change-scroll-left', callback

onDidDestroy: (callback) ->
@emitter.on 'did-destroy', callback

getTextEditor: -> @textEditor

getTextEditorHeight: -> @textEditor.getHeight() * @getVerticalScaleFactor()
Expand Down
26 changes: 25 additions & 1 deletion spec/minimap-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fs = require 'fs-plus'
{TextEditor} = require 'atom'
Minimap = require '../lib/minimap'

describe 'Minimap', ->
fdescribe 'Minimap', ->
[editor, minimap, largeSample, smallSample] = []

beforeEach ->
Expand All @@ -22,6 +22,9 @@ describe 'Minimap', ->
it 'has an associated editor', ->
expect(minimap.getTextEditor()).toEqual(editor)

it 'returns false when asked if destroyed', ->
expect(minimap.isDestroyed()).toBeFalsy()

it 'raise an exception if created without a text editor', ->
expect(-> new Minimap).toThrow()

Expand Down Expand Up @@ -143,6 +146,27 @@ describe 'Minimap', ->
it 'computes the last visible row in the minimap', ->
expect(minimap.getLastVisibleScreenRow()).toEqual(largeLineCount)

describe 'destroying the model', ->
it 'emits a did-destroy event', ->
spy = jasmine.createSpy('destroy')
minimap.onDidDestroy(spy)

minimap.destroy()

expect(spy).toHaveBeenCalled()

it 'returns true when asked if destroyed', ->
minimap.destroy()
expect(minimap.isDestroyed()).toBeTruthy()

describe 'destroying the text editor', ->
it 'destroys the model', ->
spyOn(minimap,'destroy')

editor.destroy()

expect(minimap.destroy).toHaveBeenCalled()

# ######## ######## ###### #######
# ## ## ## ## ## ## ##
# ## ## ## ## ## ##
Expand Down

0 comments on commit b65698b

Please sign in to comment.