mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2025-01-05 05:34:30 +03:00
Unsubscribe correctly from buffers in packages
Previously namespaces were used to off() when a buffer was unsubscribed from which affected other views in the same package also listening to the current buffer. Now event namespaces are no longer used and instead off() is called with the callbacks originally registered for the given event name.
This commit is contained in:
parent
2e6735ecd0
commit
461aaa83b0
@ -10,8 +10,8 @@ class GitDiffView
|
||||
@gutter = @editor.gutter
|
||||
@diffs = {}
|
||||
|
||||
@subscribe @editor, 'editor:path-changed', => @subscribeToBuffer()
|
||||
@subscribe @editor, 'editor:display-updated', => @renderDiffs()
|
||||
@subscribe @editor, 'editor:path-changed', @subscribeToBuffer
|
||||
@subscribe @editor, 'editor:display-updated', @renderDiffs
|
||||
@subscribe git, 'statuses-changed', =>
|
||||
@diffs = {}
|
||||
@scheduleUpdate()
|
||||
@ -23,22 +23,26 @@ class GitDiffView
|
||||
|
||||
beforeRemove: ->
|
||||
@unsubscribe()
|
||||
@unsubscribeFromBuffer()
|
||||
|
||||
subscribeToBuffer: ->
|
||||
unsubscribeFromBuffer: ->
|
||||
if @buffer?
|
||||
@removeDiffs()
|
||||
delete @diffs[@buffer.getPath()] if @buffer.destroyed
|
||||
@buffer.off '.git-diff'
|
||||
@buffer.off 'contents-modified', @updateDiffs
|
||||
@buffer = null
|
||||
|
||||
subscribeToBuffer: =>
|
||||
@unsubscribeFromBuffer()
|
||||
|
||||
if @buffer = @editor.getBuffer()
|
||||
@scheduleUpdate() unless @diffs[@buffer.getPath()]?
|
||||
@buffer.on 'contents-modified.git-diff', => @updateDiffs()
|
||||
@buffer.on 'contents-modified', @updateDiffs
|
||||
|
||||
scheduleUpdate: ->
|
||||
_.nextTick => @updateDiffs()
|
||||
_.nextTick(@updateDiffs)
|
||||
|
||||
updateDiffs: ->
|
||||
updateDiffs: =>
|
||||
@generateDiffs()
|
||||
@renderDiffs()
|
||||
|
||||
@ -46,12 +50,12 @@ class GitDiffView
|
||||
if path = @buffer.getPath()
|
||||
@diffs[path] = git?.getLineDiffs(path, @buffer.getText())
|
||||
|
||||
removeDiffs: ->
|
||||
removeDiffs: =>
|
||||
if @gutter.hasGitLineDiffs
|
||||
@gutter.find('.line-number').removeClass('git-line-added git-line-modified git-line-removed')
|
||||
@gutter.hasGitLineDiffs = false
|
||||
|
||||
renderDiffs: ->
|
||||
renderDiffs: =>
|
||||
return unless @gutter.isVisible()
|
||||
|
||||
@removeDiffs()
|
||||
|
@ -11,27 +11,30 @@ class SpellCheckView extends View
|
||||
views: []
|
||||
|
||||
initialize: (@editor) ->
|
||||
@subscribe @editor, 'editor:path-changed', => @subscribeToBuffer()
|
||||
@subscribe @editor, 'editor:grammar-changed', => @subscribeToBuffer()
|
||||
@observeConfig 'editor.fontSize', => @subscribeToBuffer()
|
||||
@observeConfig 'spell-check.grammars', => @subscribeToBuffer()
|
||||
@subscribe @editor, 'editor:path-changed', @subscribeToBuffer
|
||||
@subscribe @editor, 'editor:grammar-changed', @subscribeToBuffer
|
||||
@observeConfig 'editor.fontSize', @subscribeToBuffer
|
||||
@observeConfig 'spell-check.grammars', @subscribeToBuffer
|
||||
|
||||
@subscribeToBuffer()
|
||||
|
||||
beforeRemove: ->
|
||||
@unsubscribeFromBuffer()
|
||||
|
||||
unsubscribeFromBuffer: ->
|
||||
@destroyViews()
|
||||
@task?.abort()
|
||||
|
||||
if @buffer?
|
||||
@buffer.off '.spell-check'
|
||||
@buffer.off 'contents-modified', @updateMisspellings
|
||||
@buffer = null
|
||||
|
||||
subscribeToBuffer: ->
|
||||
subscribeToBuffer: =>
|
||||
@unsubscribeFromBuffer()
|
||||
|
||||
if @spellCheckCurrentGrammar()
|
||||
@buffer = @editor.getBuffer()
|
||||
@buffer.on 'contents-modified.spell-check', => @updateMisspellings()
|
||||
@buffer.on 'contents-modified', @updateMisspellings
|
||||
@updateMisspellings()
|
||||
|
||||
spellCheckCurrentGrammar: ->
|
||||
@ -49,11 +52,7 @@ class SpellCheckView extends View
|
||||
@views.push(view)
|
||||
@append(view)
|
||||
|
||||
updateMisspellings: ->
|
||||
unless @editor.activeEditSession?
|
||||
@unsubscribeFromBuffer()
|
||||
return
|
||||
|
||||
updateMisspellings: =>
|
||||
@task?.abort()
|
||||
|
||||
callback = (misspellings) =>
|
||||
|
@ -35,23 +35,31 @@ class StatusBarView extends View
|
||||
if git?
|
||||
@subscribe git, 'status-changed', (path, status) =>
|
||||
@updateStatusBar() if path is @getActiveItemPath()
|
||||
@subscribe git, 'statuses-changed', =>
|
||||
@updateStatusBar()
|
||||
@subscribe git, 'statuses-changed', @updateStatusBar
|
||||
|
||||
@subscribeToBuffer()
|
||||
|
||||
beforeRemove: ->
|
||||
@unsubscribeFromBuffer()
|
||||
|
||||
getActiveItemPath: ->
|
||||
@pane.activeItem?.getPath?()
|
||||
|
||||
unsubscribeFromBuffer: ->
|
||||
if @buffer?
|
||||
@buffer.off 'modified-status-changed', @updateBufferHasModifiedText
|
||||
@buffer.off 'saved', @updateStatusBar
|
||||
@buffer = null
|
||||
|
||||
subscribeToBuffer: ->
|
||||
@buffer?.off '.status-bar'
|
||||
@unsubscribeFromBuffer()
|
||||
if @buffer = @pane.activeItem.getBuffer?()
|
||||
@buffer.on 'modified-status-changed.status-bar', (isModified) => @updateBufferHasModifiedText(isModified)
|
||||
@buffer.on 'saved.status-bar', => @updateStatusBar()
|
||||
@buffer.on 'modified-status-changed', @updateBufferHasModifiedText
|
||||
@buffer.on 'saved', @updateStatusBar
|
||||
|
||||
@updateStatusBar()
|
||||
|
||||
updateStatusBar: ->
|
||||
updateStatusBar: =>
|
||||
@updateGrammarText()
|
||||
@updateBranchText()
|
||||
@updateBufferHasModifiedText(@buffer?.isModified())
|
||||
@ -65,7 +73,7 @@ class StatusBarView extends View
|
||||
else
|
||||
@grammarName.text(grammar.name).show()
|
||||
|
||||
updateBufferHasModifiedText: (isModified)->
|
||||
updateBufferHasModifiedText: (isModified) =>
|
||||
if isModified
|
||||
@bufferModified.text('*') unless @isModified
|
||||
@isModified = true
|
||||
|
Loading…
Reference in New Issue
Block a user