Tildify path in title bar

This will use ~/ for the path to the home directory
This commit is contained in:
Lukas Geiger 2016-08-31 20:47:09 +01:00
parent bb0b0857f4
commit 498a56a603
3 changed files with 12 additions and 8 deletions

View File

@ -81,7 +81,7 @@ describe "Workspace", ->
expect(untitledEditor.getText()).toBe("An untitled editor.")
expect(atom.workspace.getActiveTextEditor().getPath()).toBe editor3.getPath()
pathEscaped = escapeStringRegex(atom.project.getPaths()[0])
pathEscaped = fs.tildify(escapeStringRegex(atom.project.getPaths()[0]))
expect(document.title).toMatch ///^#{path.basename(editor3.getLongTitle())}\ \u2014\ #{pathEscaped}///
describe "where there are no open panes or editors", ->
@ -894,28 +894,28 @@ describe "Workspace", ->
describe "when there is an active pane item", ->
it "sets the title to the pane item's title plus the project path", ->
item = atom.workspace.getActivePaneItem()
pathEscaped = escapeStringRegex(atom.project.getPaths()[0])
pathEscaped = fs.tildify(escapeStringRegex(atom.project.getPaths()[0]))
expect(document.title).toMatch ///^#{item.getTitle()}\ \u2014\ #{pathEscaped}///
describe "when the title of the active pane item changes", ->
it "updates the window title based on the item's new title", ->
editor = atom.workspace.getActivePaneItem()
editor.buffer.setPath(path.join(temp.dir, 'hi'))
pathEscaped = escapeStringRegex(atom.project.getPaths()[0])
pathEscaped = fs.tildify(escapeStringRegex(atom.project.getPaths()[0]))
expect(document.title).toMatch ///^#{editor.getTitle()}\ \u2014\ #{pathEscaped}///
describe "when the active pane's item changes", ->
it "updates the title to the new item's title plus the project path", ->
atom.workspace.getActivePane().activateNextItem()
item = atom.workspace.getActivePaneItem()
pathEscaped = escapeStringRegex(atom.project.getPaths()[0])
pathEscaped = fs.tildify(escapeStringRegex(atom.project.getPaths()[0]))
expect(document.title).toMatch ///^#{item.getTitle()}\ \u2014\ #{pathEscaped}///
describe "when the last pane item is removed", ->
it "updates the title to contain the project's path", ->
atom.workspace.getActivePane().destroy()
expect(atom.workspace.getActivePaneItem()).toBeUndefined()
pathEscaped = escapeStringRegex(atom.project.getPaths()[0])
pathEscaped = fs.tildify(escapeStringRegex(atom.project.getPaths()[0]))
expect(document.title).toMatch ///^#{pathEscaped}///
describe "when an inactive pane's item changes", ->
@ -941,7 +941,7 @@ describe "Workspace", ->
})
workspace2.deserialize(atom.workspace.serialize(), atom.deserializers)
item = workspace2.getActivePaneItem()
pathEscaped = escapeStringRegex(atom.project.getPaths()[0])
pathEscaped = fs.tildify(escapeStringRegex(atom.project.getPaths()[0]))
expect(document.title).toMatch ///^#{item.getLongTitle()}\ \u2014\ #{pathEscaped}///
workspace2.destroy()

View File

@ -1,5 +1,6 @@
_ = require 'underscore-plus'
path = require 'path'
fs = require 'fs-plus'
Grim = require 'grim'
{CompositeDisposable, Emitter} = require 'event-kit'
{Point, Range} = TextBuffer = require 'text-buffer'
@ -803,12 +804,13 @@ class TextEditor extends Model
allPathSegments = []
for textEditor in atom.workspace.getTextEditors() when textEditor isnt this
if textEditor.getFileName() is fileName
allPathSegments.push(textEditor.getDirectoryPath().split(path.sep))
directoryPath = fs.tildify(textEditor.getDirectoryPath())
allPathSegments.push(directoryPath.split(path.sep))
if allPathSegments.length is 0
return fileName
ourPathSegments = @getDirectoryPath().split(path.sep)
ourPathSegments = fs.tildify(@getDirectoryPath()).split(path.sep)
allPathSegments.push ourPathSegments
loop

View File

@ -185,6 +185,8 @@ class Workspace extends Model
itemPath is projectPath or itemPath?.startsWith(projectPath + path.sep)
itemTitle ?= "untitled"
projectPath ?= projectPaths[0]
if projectPath?
projectPath = fs.tildify(projectPath)
titleParts = []
if item? and projectPath?