Skip to content

Commit

Permalink
🐛 Fix error raised when closing the last editor of a pane
Browse files Browse the repository at this point in the history
  • Loading branch information
abe33 committed Nov 28, 2014
1 parent abf0a13 commit 8ee359e
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions lib/atom-color-highlight-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,20 @@ 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()
@model = model
@subscribeToModel()

setEditorView: (editorView) ->
@unsubscribeFromEditor()
@editorView = editorView
{@editor} = @editorView
@subscribeToEditor()
Expand All @@ -56,13 +55,16 @@ 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
@subscriptions.add @editor.onDidAddSelection @requestSelectionUpdate
@subscriptions.add @editor.onDidRemoveSelection @requestSelectionUpdate
@subscriptions.add @editor.onDidChangeSelectionRange @requestSelectionUpdate

editorDestroyed: -> @destroy()

requestSelectionUpdate: =>
return if @updateRequested

Expand All @@ -71,10 +73,6 @@ class AtomColorHighlightView extends View
@updateSelections()
@updateRequested = false

unsubscribeFromEditor: ->
return unless @editor?
@editorSubscriptions.dispose()

updateSelections: =>
return if @markers?.length is 0

Expand All @@ -96,6 +94,7 @@ class AtomColorHighlightView extends View

# Tear down any state and detach
destroy: ->
@unsubscribeFromModel()
@subscriptions.dispose()
@destroyAllViews()
@detach()
Expand Down Expand Up @@ -158,5 +157,3 @@ class AtomColorHighlightView extends View
destroyAllViews: ->
@empty()
@markerViews = {}

asDisposable: (subscription) -> new Disposable -> subscription.off()

0 comments on commit 8ee359e

Please sign in to comment.