mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Window title is set to active editor's buffer path.
This commit is contained in:
@@ -2,6 +2,7 @@ $ = require 'jquery'
|
||||
fs = require 'fs'
|
||||
RootView = require 'root-view'
|
||||
Buffer = require 'buffer'
|
||||
Editor = require 'editor'
|
||||
|
||||
describe "RootView", ->
|
||||
rootView = null
|
||||
@@ -350,3 +351,18 @@ describe "RootView", ->
|
||||
rootView.trigger(event)
|
||||
expect(commandHandler).toHaveBeenCalled()
|
||||
|
||||
describe "document.title", ->
|
||||
it "is set to activeEditor's buffer path", ->
|
||||
expect(document.title).toBe url
|
||||
|
||||
it "only listens to focused editors path changes", ->
|
||||
editor1 = rootView.activeEditor()
|
||||
expect(document.title).toBe url
|
||||
|
||||
editor2 = rootView.activeEditor().splitLeft()
|
||||
editor2.setBuffer(new Buffer("second.txt"))
|
||||
editor2.focus()
|
||||
expect(document.title).toBe "second.txt"
|
||||
|
||||
editor1.buffer.setPath("should-not-be-title.txt")
|
||||
expect(document.title).toBe "second.txt"
|
||||
|
||||
@@ -220,7 +220,6 @@ class Editor extends View
|
||||
@trigger 'buffer-path-change'
|
||||
@buffer.on "path-change.editor#{@id}", => @trigger 'buffer-path-change'
|
||||
|
||||
document.title = @buffer.getPath()
|
||||
@renderer = new Renderer(@buffer)
|
||||
@renderLines()
|
||||
@gutter.renderLineNumbers()
|
||||
@@ -328,7 +327,6 @@ class Editor extends View
|
||||
if not @buffer.getPath()
|
||||
path = $native.saveDialog()
|
||||
return if not path
|
||||
document.title = path
|
||||
@buffer.saveAs(path)
|
||||
else
|
||||
@buffer.save()
|
||||
@@ -463,8 +461,10 @@ class Editor extends View
|
||||
|
||||
editor = new Editor({@buffer})
|
||||
editor.setCursorScreenPosition(@getCursorScreenPosition())
|
||||
|
||||
this[insertMethod](editor)
|
||||
@parents('#root-view').view().adjustSplitPanes()
|
||||
editor
|
||||
|
||||
remove: (selector, keepData) ->
|
||||
return super if keepData
|
||||
|
||||
@@ -59,6 +59,12 @@ class RootView extends View
|
||||
_.remove(@editors, editor)
|
||||
@editors.push(editor)
|
||||
|
||||
@setTitleToActiveEditorPath()
|
||||
|
||||
editor.on 'buffer-path-change.root-view', (event) =>
|
||||
e = $(event.target).view()
|
||||
@setTitleToActiveEditorPath()
|
||||
|
||||
editorRemoved: (editor) ->
|
||||
if @panes.containsElement
|
||||
_.remove(@editors, editor)
|
||||
@@ -68,13 +74,17 @@ class RootView extends View
|
||||
else
|
||||
window.close()
|
||||
|
||||
setTitleToActiveEditorPath: ->
|
||||
document.title = @activeEditor().buffer.path
|
||||
|
||||
activeEditor: ->
|
||||
if @editors.length
|
||||
_.last(@editors)
|
||||
else
|
||||
new Editor()
|
||||
.appendTo(@panes)
|
||||
.focus()
|
||||
editor = new Editor()
|
||||
@editors.push(editor)
|
||||
editor.appendTo(@panes)
|
||||
editor.focus()
|
||||
|
||||
adjustSplitPanes: (element = @panes.children(':first'))->
|
||||
if element.hasClass('row')
|
||||
|
||||
Reference in New Issue
Block a user