mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 07:28:08 +03:00
Base title updates on pane:active-item-changed events
This commit is contained in:
parent
3ae9c10ff5
commit
d6b85cf7e8
@ -179,69 +179,30 @@ describe "RootView", ->
|
||||
|
||||
window.keymap.bindKeys('*', 'x': 'foo-command')
|
||||
|
||||
describe "when a keydown event is triggered on the RootView (not originating from Ace)", ->
|
||||
describe "when a keydown event is triggered on the RootView", ->
|
||||
it "triggers matching keybindings for that event", ->
|
||||
event = keydownEvent 'x', target: rootView[0]
|
||||
|
||||
rootView.trigger(event)
|
||||
expect(commandHandler).toHaveBeenCalled()
|
||||
|
||||
describe "title", ->
|
||||
describe "when the project has no path", ->
|
||||
it "sets the title to 'untitled'", ->
|
||||
project.setPath(undefined)
|
||||
expect(rootView.title).toBe 'untitled'
|
||||
|
||||
describe "when the path of the active editor changes", ->
|
||||
it "changes the title and emits an root-view:active-path-changed event", ->
|
||||
pathChangeHandler = jasmine.createSpy 'pathChangeHandler'
|
||||
rootView.on 'root-view:active-path-changed', pathChangeHandler
|
||||
describe "when the project has a path", ->
|
||||
describe "when there is no active pane item", ->
|
||||
it "sets the title to the project's path", ->
|
||||
rootView.getActivePane().remove()
|
||||
expect(rootView.getActivePaneItem()).toBeUndefined()
|
||||
expect(rootView.title).toBe project.getPath()
|
||||
|
||||
editor1 = rootView.getActiveEditor()
|
||||
expect(rootView.getTitle()).toBe "#{fs.base(editor1.getPath())} – #{project.getPath()}"
|
||||
|
||||
editor2 = rootView.getActiveEditor().splitLeft()
|
||||
|
||||
path = project.resolve('b')
|
||||
editor2.edit(project.buildEditSession(path))
|
||||
expect(pathChangeHandler).toHaveBeenCalled()
|
||||
expect(rootView.getTitle()).toBe "#{fs.base(editor2.getPath())} – #{project.getPath()}"
|
||||
|
||||
pathChangeHandler.reset()
|
||||
editor1.getBuffer().saveAs("/tmp/should-not-be-title.txt")
|
||||
expect(pathChangeHandler).not.toHaveBeenCalled()
|
||||
expect(rootView.getTitle()).toBe "#{fs.base(editor2.getPath())} – #{project.getPath()}"
|
||||
|
||||
it "sets the project path to the directory of the editor if it was previously unassigned", ->
|
||||
project.setPath(undefined)
|
||||
window.rootView = new RootView
|
||||
rootView.open()
|
||||
expect(project.getPath()?).toBeFalsy()
|
||||
rootView.getActiveEditor().getBuffer().saveAs('/tmp/ignore-me')
|
||||
expect(project.getPath()).toBe '/tmp'
|
||||
|
||||
describe "when editors are focused", ->
|
||||
it "triggers 'root-view:active-path-changed' events if the path of the active editor actually changes", ->
|
||||
pathChangeHandler = jasmine.createSpy 'pathChangeHandler'
|
||||
rootView.on 'root-view:active-path-changed', pathChangeHandler
|
||||
|
||||
editor1 = rootView.getActiveEditor()
|
||||
editor2 = rootView.getActiveEditor().splitLeft()
|
||||
|
||||
rootView.open(require.resolve('fixtures/sample.txt'))
|
||||
expect(pathChangeHandler).toHaveBeenCalled()
|
||||
pathChangeHandler.reset()
|
||||
|
||||
editor1.focus()
|
||||
expect(pathChangeHandler).toHaveBeenCalled()
|
||||
pathChangeHandler.reset()
|
||||
|
||||
rootView.focus()
|
||||
expect(pathChangeHandler).not.toHaveBeenCalled()
|
||||
|
||||
editor2.edit(editor1.activeEditSession.copy())
|
||||
editor2.focus()
|
||||
expect(pathChangeHandler).not.toHaveBeenCalled()
|
||||
|
||||
describe "when the last editor is removed", ->
|
||||
it "updates the title to the project path", ->
|
||||
rootView.getEditors()[0].remove()
|
||||
expect(rootView.getTitle()).toBe project.getPath()
|
||||
describe "when there is an active pane item", ->
|
||||
it "sets the title to the pane item's title plus the project path", ->
|
||||
item = rootView.getActivePaneItem()
|
||||
expect(rootView.title).toBe "#{item.getTitle()} - #{project.getPath()}"
|
||||
|
||||
describe "font size adjustment", ->
|
||||
editor = null
|
||||
|
@ -56,7 +56,7 @@ beforeEach ->
|
||||
|
||||
# make editor display updates synchronous
|
||||
spyOn(Editor.prototype, 'requestDisplayUpdate').andCallFake -> @updateDisplay()
|
||||
spyOn(RootView.prototype, 'updateWindowTitle').andCallFake ->
|
||||
spyOn(RootView.prototype, 'setTitle').andCallFake (@title) ->
|
||||
spyOn(window, "setTimeout").andCallFake window.fakeSetTimeout
|
||||
spyOn(window, "clearTimeout").andCallFake window.fakeClearTimeout
|
||||
spyOn(File.prototype, "detectResurrectionAfterDelay").andCallFake -> @detectResurrection()
|
||||
|
@ -55,6 +55,9 @@ class EditSession
|
||||
getViewClass: ->
|
||||
require 'editor'
|
||||
|
||||
getTitle: ->
|
||||
fs.base(@getPath())
|
||||
|
||||
destroy: ->
|
||||
return if @destroyed
|
||||
@destroyed = true
|
||||
|
@ -39,12 +39,8 @@ class RootView extends View
|
||||
@subscribe $(window), 'focus', (e) =>
|
||||
@handleFocus(e) if document.activeElement is document.body
|
||||
|
||||
@on 'root-view:active-path-changed', (e, path) =>
|
||||
if path
|
||||
project.setPath(path) unless project.getRootDirectory()
|
||||
@setTitle(fs.base(path))
|
||||
else
|
||||
@setTitle("untitled")
|
||||
project.on 'path-changed', => @updateTitle()
|
||||
@on 'pane:active-item-changed', => @updateTitle()
|
||||
|
||||
@command 'window:increase-font-size', =>
|
||||
config.set("editor.fontSize", config.get("editor.fontSize") + 1)
|
||||
@ -124,22 +120,18 @@ class RootView extends View
|
||||
if not previousActiveEditor or editor.getPath() != previousActiveEditor.getPath()
|
||||
@trigger 'root-view:active-path-changed', editor.getPath()
|
||||
|
||||
getTitle: ->
|
||||
@title or "untitled"
|
||||
|
||||
updateTitle: ->
|
||||
if projectPath = project.getPath()
|
||||
if item = @getActivePaneItem()
|
||||
@setTitle("#{item.getTitle()} - #{projectPath}")
|
||||
else
|
||||
@setTitle(projectPath)
|
||||
else
|
||||
@setTitle('untitled')
|
||||
|
||||
setTitle: (title) ->
|
||||
projectPath = project.getPath()
|
||||
if not projectPath
|
||||
@title = "untitled"
|
||||
else if title
|
||||
@title = "#{title} – #{projectPath}"
|
||||
else
|
||||
@title = projectPath
|
||||
|
||||
@updateWindowTitle()
|
||||
|
||||
updateWindowTitle: ->
|
||||
document.title = @title
|
||||
document.title = title
|
||||
|
||||
getEditors: ->
|
||||
@panes.find('.pane > .item-views > .editor').map(-> $(this).view()).toArray()
|
||||
|
Loading…
Reference in New Issue
Block a user