mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-27 15:53:31 +03:00
tab titles are relative to cwd if prefixes match
This commit is contained in:
parent
5c045c49aa
commit
7d68ac3619
@ -22,10 +22,29 @@ final class Tab<Rep: TabRepresentative>: NSView {
|
||||
self.adjustToSelectionChange(newValue.isSelected)
|
||||
}
|
||||
didSet {
|
||||
if self.titleView.stringValue == self.title { return }
|
||||
self.titleView.stringValue = self.title
|
||||
updateTitle(self.title)
|
||||
}
|
||||
}
|
||||
|
||||
private func updateTitle(_ title: String) {
|
||||
let display_title = displayTitle(title)
|
||||
if self.titleView.stringValue == display_title { return }
|
||||
self.titleView.stringValue = display_title
|
||||
self.adjustWidth()
|
||||
}
|
||||
|
||||
private func displayTitle(_ title: String) -> String {
|
||||
var display_title = title
|
||||
if self.tabBar?.cwd != nil {
|
||||
let cwd = ((self.tabBar?.cwd!)! as NSString).abbreviatingWithTildeInPath
|
||||
let pref = title.commonPrefix(with: cwd)
|
||||
if pref == cwd {
|
||||
let cwd_component_count = (cwd as NSString).pathComponents.count
|
||||
display_title = NSString.path(
|
||||
withComponents: Array((title as NSString).pathComponents[cwd_component_count...]))
|
||||
}
|
||||
}
|
||||
return display_title
|
||||
}
|
||||
|
||||
init(withTabRepresentative tabRepresentative: Rep, in tabBar: TabBar<Rep>) {
|
||||
@ -50,6 +69,10 @@ final class Tab<Rep: TabRepresentative>: NSView {
|
||||
self.adjustColors(self.isSelected)
|
||||
}
|
||||
|
||||
func updateContext() {
|
||||
updateTitle(self.title)
|
||||
}
|
||||
|
||||
override func mouseUp(with _: NSEvent) { self.tabBar?.select(tab: self) }
|
||||
|
||||
override func draw(_: NSRect) {
|
||||
|
@ -15,6 +15,11 @@ public final class TabBar<Rep: TabRepresentative>: NSView {
|
||||
public typealias TabCallback = (Int, Rep, [Rep]) -> Void
|
||||
|
||||
public var theme: Theme { self._theme }
|
||||
public var cwd: String? {
|
||||
didSet {
|
||||
self.tabs.forEach { $0.updateContext() }
|
||||
}
|
||||
}
|
||||
|
||||
public var closeHandler: TabCallback?
|
||||
public var selectHandler: TabCallback?
|
||||
|
@ -344,6 +344,7 @@ final class MainWindow: NSObject,
|
||||
|
||||
if let cwd = state.cwdToSet {
|
||||
self.neoVimView.cwd = cwd
|
||||
self.neoVimView.tabBar?.cwd = cwd.path
|
||||
}
|
||||
|
||||
Completable
|
||||
|
Loading…
Reference in New Issue
Block a user