mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-11 04:48:44 +03:00
Update the buffer being used when the editor path changes
Previously the status indicator would only work for the first buffer open since only the buffer used when the extension was initialized was subscribed to for change events.
This commit is contained in:
parent
0da869589e
commit
6551be0c85
@ -1,6 +1,7 @@
|
||||
$ = require 'jquery'
|
||||
RootView = require 'root-view'
|
||||
StatusBar = require 'status-bar'
|
||||
fs = require 'fs'
|
||||
|
||||
describe "StatusBar", ->
|
||||
[rootView, editor, statusBar, buffer] = []
|
||||
@ -55,6 +56,9 @@ describe "StatusBar", ->
|
||||
|
||||
describe "when the buffer content has changed from the content on disk", ->
|
||||
it "disables the buffer modified indicator on save", ->
|
||||
path = "/tmp/atom-whitespace.txt"
|
||||
fs.write(path, "")
|
||||
rootView.open(path)
|
||||
expect(statusBar.bufferModified.text()).toBe ''
|
||||
editor.insertText("\n")
|
||||
expect(statusBar.bufferModified.text()).toBe '*'
|
||||
@ -75,6 +79,20 @@ describe "StatusBar", ->
|
||||
editor.undo()
|
||||
expect(statusBar.bufferModified.text()).toBe ''
|
||||
|
||||
describe "when the buffer changes", ->
|
||||
it "updates the buffer modified indicator for the new buffer", ->
|
||||
expect(statusBar.bufferModified.text()).toBe ''
|
||||
rootView.open(require.resolve('fixtures/sample.txt'))
|
||||
editor.insertText("\n")
|
||||
expect(statusBar.bufferModified.text()).toBe '*'
|
||||
|
||||
it "doesn't update the buffer modified indicator for the old buffer", ->
|
||||
oldBuffer = editor.getBuffer()
|
||||
expect(statusBar.bufferModified.text()).toBe ''
|
||||
rootView.open(require.resolve('fixtures/sample.txt'))
|
||||
oldBuffer.setText("new text")
|
||||
expect(statusBar.bufferModified.text()).toBe ''
|
||||
|
||||
describe "when the associated editor's cursor position changes", ->
|
||||
it "updates the cursor position in the status bar", ->
|
||||
editor.setCursorScreenPosition([1, 2])
|
||||
|
@ -24,18 +24,24 @@ class StatusBar extends View
|
||||
|
||||
initialize: (@rootView, @editor) ->
|
||||
@updatePathText()
|
||||
@editor.on 'editor-path-change', => @updatePathText()
|
||||
@editor.on 'editor-path-change', =>
|
||||
@subscribeToBuffer()
|
||||
@updatePathText()
|
||||
|
||||
@updateCursorPositionText()
|
||||
@editor.on 'cursor-move', => @updateCursorPositionText()
|
||||
|
||||
@subscribeToBuffer()
|
||||
|
||||
subscribeToBuffer: ->
|
||||
@buffer?.off '.status-bar'
|
||||
@buffer = @editor.getBuffer()
|
||||
@buffer.on 'change.status-bar', => @updateBufferModifiedText()
|
||||
@buffer.on 'after-save.status-bar', => @updateBufferModifiedText()
|
||||
@updateBufferModifiedText()
|
||||
@editor.getBuffer().on 'change', => @updateBufferModifiedText()
|
||||
@editor.getBuffer().on 'after-save', => @updateBufferModifiedText()
|
||||
|
||||
updateBufferModifiedText: ->
|
||||
buffer = @editor.getBuffer()
|
||||
if buffer.isModified() and buffer.contentDifferentOnDisk()
|
||||
if @buffer.isModified() and @buffer.contentDifferentOnDisk()
|
||||
@bufferModified.text('*')
|
||||
else
|
||||
@bufferModified.text('')
|
||||
|
Loading…
Reference in New Issue
Block a user