From 012237678ee278653e1ed2f57c9fdcdbe88ac3e1 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 17 Apr 2012 12:09:06 -0600 Subject: [PATCH] Status bar renders current path and buffer position on initialization --- spec/app/status-bar-spec.coffee | 19 +++++++++++++++++-- src/app/status-bar.coffee | 22 ++++++++++++++++------ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/spec/app/status-bar-spec.coffee b/spec/app/status-bar-spec.coffee index bc67f3a1b..cdc3da504 100644 --- a/spec/app/status-bar-spec.coffee +++ b/spec/app/status-bar-spec.coffee @@ -3,12 +3,13 @@ RootView = require 'root-view' StatusBar = require 'status-bar' describe "StatusBar", -> - rootView = null + [rootView, statusBar] = [] beforeEach -> - rootView = new RootView + rootView = new RootView(pathToOpen: require.resolve('fixtures/sample.js')) rootView.simulateDomAttachment() StatusBar.initialize(rootView) + statusBar = rootView.find('.status-bar').view() describe "@initialize", -> it "appends a status bar to all existing and new editors", -> @@ -17,3 +18,17 @@ describe "StatusBar", -> rootView.activeEditor().splitRight() expect(rootView.find('.pane').length).toBe 2 expect(rootView.panes.find('.pane > .status-bar').length).toBe 2 + + describe ".initialize(editor)", -> + it "displays the editor's buffer path and cursor buffer position", -> + expect(statusBar.currentPath.text()).toBe 'sample.js' + expect(statusBar.cursorPosition.text()).toBe '0,0' + + describe "when associated with an unsaved buffer", -> + it "displays 'untitled' instead of the buffer's path, but still displays the buffer position", -> + rootView = new RootView + rootView.simulateDomAttachment() + StatusBar.initialize(rootView) + statusBar = rootView.find('.status-bar').view() + expect(statusBar.currentPath.text()).toBe 'untitled' + expect(statusBar.cursorPosition.text()).toBe '0,0' diff --git a/src/app/status-bar.coffee b/src/app/status-bar.coffee index fed28d98d..8b4ac2e80 100644 --- a/src/app/status-bar.coffee +++ b/src/app/status-bar.coffee @@ -4,16 +4,26 @@ module.exports = class StatusBar extends View @initialize: (rootView) -> for editor in rootView.editors() - @appendToEditorPane(editor) + @appendToEditorPane(rootView, editor) rootView.on 'editor-open', (e, editor) => - @appendToEditorPane(editor) + @appendToEditorPane(rootView, editor) - @appendToEditorPane: (editor) -> + @appendToEditorPane: (rootView, editor) -> if pane = editor.pane() - pane.append(new StatusBar(editor)) + pane.append(new StatusBar(rootView, editor)) @content: -> - @div class: 'status-bar' + @div class: 'status-bar', => + @div class: 'current-path', outlet: 'currentPath' + @div class: 'cursor-position', outlet: 'cursorPosition' - initialize: (@editor) -> + initialize: (@rootView, @editor) -> + path = @editor.buffer.path + if path + @currentPath.text(@rootView.project.relativize(path)) + else + @currentPath.text('untitled') + + position = @editor.getCursorBufferPosition() + @cursorPosition.text("#{position.row},#{position.column}")