From 8ee359ebb17b96cfae8dc2174d22f2d2c102198d Mon Sep 17 00:00:00 2001 From: abe33 Date: Fri, 28 Nov 2014 12:01:32 +0100 Subject: [PATCH] :bug: Fix error raised when closing the last editor of a pane --- lib/atom-color-highlight-view.coffee | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/atom-color-highlight-view.coffee b/lib/atom-color-highlight-view.coffee index b8c7b9a..2cd637f 100644 --- a/lib/atom-color-highlight-view.coffee +++ b/lib/atom-color-highlight-view.coffee @@ -27,13 +27,13 @@ class AtomColorHighlightView extends View @updateSelections() observeConfig: -> - @subscriptions.add @asDisposable atom.config.observe 'atom-color-highlight.hideMarkersInComments', @rebuildMarkers - @subscriptions.add @asDisposable atom.config.observe 'atom-color-highlight.hideMarkersInStrings', @rebuildMarkers - @subscriptions.add @asDisposable atom.config.observe 'atom-color-highlight.markersAtEndOfLine', @rebuildMarkers - @subscriptions.add @asDisposable atom.config.observe 'atom-color-highlight.dotMarkersSize', @rebuildMarkers - @subscriptions.add @asDisposable atom.config.observe 'atom-color-highlight.dotMarkersSpading', @rebuildMarkers - @subscriptions.add @asDisposable atom.config.observe 'editor.lineHeight', @rebuildMarkers - @subscriptions.add @asDisposable atom.config.observe 'editor.fontSize', @rebuildMarkers + @subscriptions.add atom.config.observe 'atom-color-highlight.hideMarkersInComments', @rebuildMarkers + @subscriptions.add atom.config.observe 'atom-color-highlight.hideMarkersInStrings', @rebuildMarkers + @subscriptions.add atom.config.observe 'atom-color-highlight.markersAtEndOfLine', @rebuildMarkers + @subscriptions.add atom.config.observe 'atom-color-highlight.dotMarkersSize', @rebuildMarkers + @subscriptions.add atom.config.observe 'atom-color-highlight.dotMarkersSpading', @rebuildMarkers + @subscriptions.add atom.config.observe 'editor.lineHeight', @rebuildMarkers + @subscriptions.add atom.config.observe 'editor.fontSize', @rebuildMarkers setModel: (model) -> @unsubscribeFromModel() @@ -41,7 +41,6 @@ class AtomColorHighlightView extends View @subscribeToModel() setEditorView: (editorView) -> - @unsubscribeFromEditor() @editorView = editorView {@editor} = @editorView @subscribeToEditor() @@ -56,6 +55,7 @@ class AtomColorHighlightView extends View subscribeToEditor: -> return unless @editor? + @subscriptions.add @editor.onDidDestroy @editorDestroyed @subscriptions.add @editor.onDidAddCursor @requestSelectionUpdate @subscriptions.add @editor.onDidRemoveCursor @requestSelectionUpdate @subscriptions.add @editor.onDidChangeCursorPosition @requestSelectionUpdate @@ -63,6 +63,8 @@ class AtomColorHighlightView extends View @subscriptions.add @editor.onDidRemoveSelection @requestSelectionUpdate @subscriptions.add @editor.onDidChangeSelectionRange @requestSelectionUpdate + editorDestroyed: -> @destroy() + requestSelectionUpdate: => return if @updateRequested @@ -71,10 +73,6 @@ class AtomColorHighlightView extends View @updateSelections() @updateRequested = false - unsubscribeFromEditor: -> - return unless @editor? - @editorSubscriptions.dispose() - updateSelections: => return if @markers?.length is 0 @@ -96,6 +94,7 @@ class AtomColorHighlightView extends View # Tear down any state and detach destroy: -> + @unsubscribeFromModel() @subscriptions.dispose() @destroyAllViews() @detach() @@ -158,5 +157,3 @@ class AtomColorHighlightView extends View destroyAllViews: -> @empty() @markerViews = {} - - asDisposable: (subscription) -> new Disposable -> subscription.off()