Update the status bar asynchronously on cursor move / buffer change

This keeps it out of the synchronous path from pressing a key to seeing it inserted on screen.
This commit is contained in:
Nathan Sobo 2012-11-02 15:46:33 -06:00
parent 9bca73816c
commit 3fbf5653c4
2 changed files with 9 additions and 3 deletions

View File

@ -1,4 +1,5 @@
$ = require 'jquery'
_ = require 'underscore'
RootView = require 'root-view'
StatusBar = require 'status-bar'
fs = require 'fs'
@ -14,6 +15,10 @@ describe "StatusBar", ->
statusBar = rootView.find('.status-bar').view()
buffer = editor.getBuffer()
# updating the status bar is asynchronous for performance reasons
# for testing purposes, make it synchronous
spyOn(_, 'defer').andCallFake (fn) -> fn()
afterEach ->
rootView.remove()

View File

@ -1,4 +1,5 @@
{View} = require 'space-pen'
_ = require 'underscore'
module.exports =
class StatusBar extends View
@ -29,15 +30,15 @@ class StatusBar extends View
@updatePathText()
@updateCursorPositionText()
@editor.on 'cursor-move', => @updateCursorPositionText()
@editor.on 'cursor-move', => _.defer => @updateCursorPositionText()
@subscribeToBuffer()
subscribeToBuffer: ->
@buffer?.off '.status-bar'
@buffer = @editor.getBuffer()
@buffer.on 'change.status-bar', => @updateBufferModifiedText()
@buffer.on 'after-save.status-bar', => @updateBufferModifiedText()
@buffer.on 'change.status-bar', => _.defer => @updateBufferModifiedText()
@buffer.on 'after-save.status-bar', => _.defer => @updateBufferModifiedText()
@updateBufferModifiedText()
updateBufferModifiedText: ->