mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Ensure custom title bar is always updated when document.title changes
This commit uses a new private API on Workspace that emits an event every time the window title gets updated (e.g. as a result of an active pane item changing, the project paths changing, etc.). This fixes a bug that left the custom title bar with a stale document.title under some circumstances. Signed-off-by: Jason Rudolph <jasonrudolph@github.com>
This commit is contained in:
committed by
Jason Rudolph
parent
5a8dce1175
commit
62ee913567
@@ -1,22 +1,27 @@
|
||||
TitleBar = require '../src/title-bar'
|
||||
temp = require 'temp'
|
||||
|
||||
describe "TitleBar", ->
|
||||
it "updates the title based on document.title when the active pane item changes", ->
|
||||
it "updates its title when document.title changes", ->
|
||||
titleBar = new TitleBar({
|
||||
workspace: atom.workspace,
|
||||
themes: atom.themes,
|
||||
applicationDelegate: atom.applicationDelegate,
|
||||
})
|
||||
expect(titleBar.element.querySelector('.title').textContent).toBe(document.title)
|
||||
|
||||
expect(titleBar.element.querySelector('.title').textContent).toBe document.title
|
||||
initialTitle = document.title
|
||||
paneItem = new FakePaneItem('Title 1')
|
||||
atom.workspace.getActivePane().activateItem(paneItem)
|
||||
expect(document.title).toMatch('Title 1')
|
||||
expect(titleBar.element.querySelector('.title').textContent).toBe(document.title)
|
||||
|
||||
atom.workspace.getActivePane().activateItem({
|
||||
getTitle: -> 'Test Title'
|
||||
})
|
||||
paneItem.setTitle('Title 2')
|
||||
expect(document.title).toMatch('Title 2')
|
||||
expect(titleBar.element.querySelector('.title').textContent).toBe(document.title)
|
||||
|
||||
expect(document.title).not.toBe(initialTitle)
|
||||
expect(titleBar.element.querySelector('.title').textContent).toBe document.title
|
||||
atom.project.setPaths([temp.mkdirSync('project-1')])
|
||||
expect(document.title).toMatch('project-1')
|
||||
expect(titleBar.element.querySelector('.title').textContent).toBe(document.title)
|
||||
|
||||
it "can update the sheet offset for the current window based on its height", ->
|
||||
titleBar = new TitleBar({
|
||||
@@ -24,6 +29,19 @@ describe "TitleBar", ->
|
||||
themes: atom.themes,
|
||||
applicationDelegate: atom.applicationDelegate,
|
||||
})
|
||||
expect(->
|
||||
titleBar.updateWindowSheetOffset()
|
||||
).not.toThrow()
|
||||
expect(-> titleBar.updateWindowSheetOffset()).not.toThrow()
|
||||
|
||||
class FakePaneItem
|
||||
constructor: (title) ->
|
||||
@title = title
|
||||
|
||||
getTitle: ->
|
||||
@title
|
||||
|
||||
onDidChangeTitle: (callback) ->
|
||||
@didChangeTitleCallback = callback
|
||||
{dispose: => @didChangeTitleCallback = null}
|
||||
|
||||
setTitle: (title) ->
|
||||
@title = title
|
||||
@didChangeTitleCallback?(title)
|
||||
|
||||
@@ -10,7 +10,7 @@ class TitleBar
|
||||
|
||||
@element.addEventListener 'dblclick', @dblclickHandler
|
||||
|
||||
@workspace.onDidChangeActivePaneItem => @updateTitle()
|
||||
@workspace.onDidChangeWindowTitle => @updateTitle()
|
||||
@themes.onDidChangeActiveThemes => @updateWindowSheetOffset()
|
||||
|
||||
@updateTitle()
|
||||
|
||||
@@ -587,6 +587,7 @@ module.exports = class Workspace extends Model {
|
||||
|
||||
document.title = titleParts.join(' \u2014 ')
|
||||
this.applicationDelegate.setRepresentedFilename(representedPath)
|
||||
this.emitter.emit('did-change-window-title')
|
||||
}
|
||||
|
||||
// On macOS, fades the application window's proxy icon when the current file
|
||||
@@ -864,6 +865,10 @@ module.exports = class Workspace extends Model {
|
||||
return this.emitter.on('did-add-text-editor', callback)
|
||||
}
|
||||
|
||||
onDidChangeWindowTitle (callback) {
|
||||
return this.emitter.on('did-change-window-title', callback)
|
||||
}
|
||||
|
||||
/*
|
||||
Section: Opening
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user