mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-10 10:17:11 +03:00
Upgrade text-buffer for event subscription methods
This commit is contained in:
parent
b9e90f2fdd
commit
a947a357f4
@ -57,7 +57,7 @@
|
||||
"serializable": "^1",
|
||||
"space-pen": "3.4.6",
|
||||
"temp": "0.7.0",
|
||||
"text-buffer": "^3.1.0",
|
||||
"text-buffer": "^3.2.0",
|
||||
"theorist": "^1.0.2",
|
||||
"underscore-plus": "^1.5.1",
|
||||
"vm-compatibility-layer": "0.1.0"
|
||||
|
@ -253,10 +253,10 @@ describe "Git", ->
|
||||
|
||||
statusHandler = jasmine.createSpy('statusHandler')
|
||||
atom.project.getRepo().on 'status-changed', statusHandler
|
||||
editor.getBuffer().emit 'path-changed'
|
||||
editor.getBuffer().emitter.emit 'did-change-path'
|
||||
expect(statusHandler.callCount).toBe 1
|
||||
expect(statusHandler).toHaveBeenCalledWith editor.getPath(), 256
|
||||
editor.getBuffer().emit 'path-changed'
|
||||
editor.getBuffer().emitter.emit 'did-change-path'
|
||||
expect(statusHandler.callCount).toBe 1
|
||||
|
||||
describe "when a project is deserialized", ->
|
||||
|
@ -22,8 +22,8 @@ class DisplayBufferMarker
|
||||
@oldTailScreenPosition = @getTailScreenPosition()
|
||||
@wasValid = @isValid()
|
||||
|
||||
@subscribe @bufferMarker, 'destroyed', => @destroyed()
|
||||
@subscribe @bufferMarker, 'changed', (event) => @notifyObservers(event)
|
||||
@subscribe @bufferMarker.onDidDestroy => @destroyed()
|
||||
@subscribe @bufferMarker.onDidChange (event) => @notifyObservers(event)
|
||||
|
||||
copy: (attributes) ->
|
||||
@displayBuffer.getMarker(@bufferMarker.copy(attributes).id)
|
||||
|
@ -55,8 +55,8 @@ class DisplayBuffer extends Model
|
||||
@subscribe @tokenizedBuffer, 'grammar-changed', (grammar) => @emit 'grammar-changed', grammar
|
||||
@subscribe @tokenizedBuffer, 'tokenized', => @emit 'tokenized'
|
||||
@subscribe @tokenizedBuffer, 'changed', @handleTokenizedBufferChange
|
||||
@subscribe @buffer, 'markers-updated', @handleBufferMarkersUpdated
|
||||
@subscribe @buffer, 'marker-created', @handleBufferMarkerCreated
|
||||
@subscribe @buffer.onDidUpdateMarkers @handleBufferMarkersUpdated
|
||||
@subscribe @buffer.onDidCreateMarker @handleBufferMarkerCreated
|
||||
|
||||
@subscribe @$softWrap, (softWrap) =>
|
||||
@emit 'soft-wrap-changed', softWrap
|
||||
|
@ -253,15 +253,15 @@ class Editor extends Model
|
||||
|
||||
subscribeToBuffer: ->
|
||||
@buffer.retain()
|
||||
@subscribe @buffer, "path-changed", =>
|
||||
@subscribe @buffer.onDidChangePath =>
|
||||
unless atom.project.getPath()?
|
||||
atom.project.setPath(path.dirname(@getPath()))
|
||||
@emit "title-changed"
|
||||
@emit "path-changed"
|
||||
@subscribe @buffer, "contents-modified", => @emit "contents-modified"
|
||||
@subscribe @buffer, "contents-conflicted", => @emit "contents-conflicted"
|
||||
@subscribe @buffer, "modified-status-changed", => @emit "modified-status-changed"
|
||||
@subscribe @buffer, "destroyed", => @destroy()
|
||||
@subscribe @buffer.onDidStopChanging => @emit "contents-modified"
|
||||
@subscribe @buffer.onDidConflict => @emit "contents-conflicted"
|
||||
@subscribe @buffer.onDidChangeModified => @emit "modified-status-changed"
|
||||
@subscribe @buffer.onDidDestroy => @destroy()
|
||||
@preserveCursorPositionOnBufferReload()
|
||||
|
||||
subscribeToDisplayBuffer: ->
|
||||
@ -1821,9 +1821,9 @@ class Editor extends Model
|
||||
|
||||
preserveCursorPositionOnBufferReload: ->
|
||||
cursorPosition = null
|
||||
@subscribe @buffer, "will-reload", =>
|
||||
@subscribe @buffer.onWillReload =>
|
||||
cursorPosition = @getCursorBufferPosition()
|
||||
@subscribe @buffer, "reloaded", =>
|
||||
@subscribe @buffer.onDidReload =>
|
||||
@setCursorBufferPosition(cursorPosition) if cursorPosition
|
||||
cursorPosition = null
|
||||
|
||||
|
@ -14,8 +14,8 @@ class Fold
|
||||
@id = @marker.id
|
||||
@displayBuffer.foldsByMarkerId[@marker.id] = this
|
||||
@updateDisplayBuffer()
|
||||
@marker.on 'destroyed', => @destroyed()
|
||||
@marker.on 'changed', ({isValid}) => @destroy() unless isValid
|
||||
@marker.onDidDestroy => @destroyed()
|
||||
@marker.onDidChange ({isValid}) => @destroy() unless isValid
|
||||
|
||||
# Returns whether this fold is contained within another fold
|
||||
isInsideLargerFold: ->
|
||||
|
@ -88,10 +88,14 @@ class Git
|
||||
|
||||
# Subscribes to buffer events.
|
||||
subscribeToBuffer: (buffer) ->
|
||||
@subscribe buffer, 'saved reloaded path-changed', =>
|
||||
getBufferPathStatus = =>
|
||||
if path = buffer.getPath()
|
||||
@getPathStatus(path)
|
||||
@subscribe buffer, 'destroyed', => @unsubscribe(buffer)
|
||||
|
||||
@subscribe buffer.onDidSave(getBufferPathStatus)
|
||||
@subscribe buffer.onDidReload(getBufferPathStatus)
|
||||
@subscribe buffer.onDidChangePath(getBufferPathStatus)
|
||||
@subscribe buffer.onDidDestroy => @unsubscribe(buffer)
|
||||
|
||||
# Subscribes to editor view event.
|
||||
checkoutHeadForEditor: (editor) ->
|
||||
|
@ -49,7 +49,7 @@ class Project extends Model
|
||||
|
||||
for buffer in @buffers
|
||||
do (buffer) =>
|
||||
buffer.once 'destroyed', => @removeBuffer(buffer)
|
||||
buffer.onDidDestroy => @removeBuffer(buffer)
|
||||
|
||||
@setPath(path)
|
||||
|
||||
@ -216,11 +216,11 @@ class Project extends Model
|
||||
|
||||
addBuffer: (buffer, options={}) ->
|
||||
@addBufferAtIndex(buffer, @buffers.length, options)
|
||||
buffer.once 'destroyed', => @removeBuffer(buffer)
|
||||
buffer.onDidDestroy => @removeBuffer(buffer)
|
||||
|
||||
addBufferAtIndex: (buffer, index, options={}) ->
|
||||
@buffers.splice(index, 0, buffer)
|
||||
buffer.once 'destroyed', => @removeBuffer(buffer)
|
||||
buffer.onDidDestroy => @removeBuffer(buffer)
|
||||
@emit 'buffer-created', buffer
|
||||
buffer
|
||||
|
||||
|
@ -51,7 +51,7 @@ class SelectListView extends View
|
||||
# This method can be overridden by subclasses but `super` should always
|
||||
# be called.
|
||||
initialize: ->
|
||||
@filterEditorView.getEditor().getBuffer().on 'changed', =>
|
||||
@filterEditorView.getEditor().getBuffer().onDidChange =>
|
||||
@schedulePopulateList()
|
||||
@filterEditorView.hiddenInput.on 'focusout', =>
|
||||
@cancel() unless @cancelling
|
||||
|
@ -30,10 +30,8 @@ class TokenizedBuffer extends Model
|
||||
@setGrammar(grammar, newScore) if newScore > @currentGrammarScore
|
||||
|
||||
@on 'grammar-changed grammar-updated', => @retokenizeLines()
|
||||
@subscribe @buffer, "changed", (e) => @handleBufferChange(e)
|
||||
@subscribe @buffer, "path-changed", =>
|
||||
@bufferPath = @buffer.getPath()
|
||||
@reloadGrammar()
|
||||
@subscribe @buffer.onDidChange (e) => @handleBufferChange(e)
|
||||
@subscribe @buffer.onDidChangePath (@bufferPath) => @reloadGrammar()
|
||||
|
||||
@subscribe @$tabLength.changes, (tabLength) => @retokenizeLines()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user