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,12 +22,31 @@ final class Tab<Rep: TabRepresentative>: NSView {
|
|||||||
self.adjustToSelectionChange(newValue.isSelected)
|
self.adjustToSelectionChange(newValue.isSelected)
|
||||||
}
|
}
|
||||||
didSet {
|
didSet {
|
||||||
if self.titleView.stringValue == self.title { return }
|
updateTitle(self.title)
|
||||||
self.titleView.stringValue = self.title
|
|
||||||
self.adjustWidth()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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>) {
|
init(withTabRepresentative tabRepresentative: Rep, in tabBar: TabBar<Rep>) {
|
||||||
self.tabBar = tabBar
|
self.tabBar = tabBar
|
||||||
self.tabRepresentative = tabRepresentative
|
self.tabRepresentative = tabRepresentative
|
||||||
@ -50,6 +69,10 @@ final class Tab<Rep: TabRepresentative>: NSView {
|
|||||||
self.adjustColors(self.isSelected)
|
self.adjustColors(self.isSelected)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateContext() {
|
||||||
|
updateTitle(self.title)
|
||||||
|
}
|
||||||
|
|
||||||
override func mouseUp(with _: NSEvent) { self.tabBar?.select(tab: self) }
|
override func mouseUp(with _: NSEvent) { self.tabBar?.select(tab: self) }
|
||||||
|
|
||||||
override func draw(_: NSRect) {
|
override func draw(_: NSRect) {
|
||||||
|
@ -15,6 +15,11 @@ public final class TabBar<Rep: TabRepresentative>: NSView {
|
|||||||
public typealias TabCallback = (Int, Rep, [Rep]) -> Void
|
public typealias TabCallback = (Int, Rep, [Rep]) -> Void
|
||||||
|
|
||||||
public var theme: Theme { self._theme }
|
public var theme: Theme { self._theme }
|
||||||
|
public var cwd: String? {
|
||||||
|
didSet {
|
||||||
|
self.tabs.forEach { $0.updateContext() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public var closeHandler: TabCallback?
|
public var closeHandler: TabCallback?
|
||||||
public var selectHandler: TabCallback?
|
public var selectHandler: TabCallback?
|
||||||
|
@ -344,6 +344,7 @@ final class MainWindow: NSObject,
|
|||||||
|
|
||||||
if let cwd = state.cwdToSet {
|
if let cwd = state.cwdToSet {
|
||||||
self.neoVimView.cwd = cwd
|
self.neoVimView.cwd = cwd
|
||||||
|
self.neoVimView.tabBar?.cwd = cwd.path
|
||||||
}
|
}
|
||||||
|
|
||||||
Completable
|
Completable
|
||||||
|
Loading…
Reference in New Issue
Block a user