mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Status bar renders current path and buffer position on initialization
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user