From 3fbf5653c443630ef586e0bd2d60a1979c29739a Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 2 Nov 2012 15:46:33 -0600 Subject: [PATCH] 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. --- spec/app/status-bar-spec.coffee | 5 +++++ src/app/status-bar.coffee | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/spec/app/status-bar-spec.coffee b/spec/app/status-bar-spec.coffee index f632b4594..9027afd36 100644 --- a/spec/app/status-bar-spec.coffee +++ b/spec/app/status-bar-spec.coffee @@ -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() diff --git a/src/app/status-bar.coffee b/src/app/status-bar.coffee index ed667a179..5de9ac79f 100644 --- a/src/app/status-bar.coffee +++ b/src/app/status-bar.coffee @@ -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: ->