From b65698bb487c5d6a09cd95b263e861cef946ae04 Mon Sep 17 00:00:00 2001 From: abe33 Date: Wed, 17 Dec 2014 19:52:01 +0100 Subject: [PATCH] Implement minimap model destruction --- lib/minimap.coffee | 9 +++++++++ spec/minimap-spec.coffee | 26 +++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/minimap.coffee b/lib/minimap.coffee index 928d242f..718b66a2 100644 --- a/lib/minimap.coffee +++ b/lib/minimap.coffee @@ -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 @@ -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() diff --git a/spec/minimap-spec.coffee b/spec/minimap-spec.coffee index 0e4452d0..f8f86f67 100644 --- a/spec/minimap-spec.coffee +++ b/spec/minimap-spec.coffee @@ -2,7 +2,7 @@ fs = require 'fs-plus' {TextEditor} = require 'atom' Minimap = require '../lib/minimap' -describe 'Minimap', -> +fdescribe 'Minimap', -> [editor, minimap, largeSample, smallSample] = [] beforeEach -> @@ -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() @@ -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() + # ######## ######## ###### ####### # ## ## ## ## ## ## ## # ## ## ## ## ## ##