From 498a56a603fcc3ea826d64ac0a1f2fd01b8d6805 Mon Sep 17 00:00:00 2001 From: Lukas Geiger Date: Wed, 31 Aug 2016 20:47:09 +0100 Subject: [PATCH] Tildify path in title bar This will use ~/ for the path to the home directory --- spec/workspace-spec.coffee | 12 ++++++------ src/text-editor.coffee | 6 ++++-- src/workspace.coffee | 2 ++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index a9d984049..ff9b957bf 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -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() diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 69eabbbd8..1224cb70e 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -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 diff --git a/src/workspace.coffee b/src/workspace.coffee index aa2b4ae79..7439a6c53 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -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?