macOS: fix title misalignment in tabs (#9168)
While I was testing #9166, noticed another edge case🤯. This appears both in Tahoe and Sequoia👇🏻 https://github.com/user-attachments/assets/9cecea35-1241-4f31-9c15-0f2a7a6f342a1.2.x
parent
5c9ceab0bf
commit
0af32d06b5
|
|
@ -170,9 +170,16 @@ class TerminalWindow: NSWindow {
|
||||||
|
|
||||||
/// Returns true if there is a tab bar visible on this window.
|
/// Returns true if there is a tab bar visible on this window.
|
||||||
var hasTabBar: Bool {
|
var hasTabBar: Bool {
|
||||||
|
// TODO: use titlebarView to find it instead
|
||||||
contentView?.firstViewFromRoot(withClassName: "NSTabBar") != nil
|
contentView?.firstViewFromRoot(withClassName: "NSTabBar") != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var hasMoreThanOneTabs: Bool {
|
||||||
|
/// accessing ``tabGroup?.windows`` here
|
||||||
|
/// will cause other edge cases, be careful
|
||||||
|
(tabbedWindows?.count ?? 0) > 1
|
||||||
|
}
|
||||||
|
|
||||||
func isTabBar(_ childViewController: NSTitlebarAccessoryViewController) -> Bool {
|
func isTabBar(_ childViewController: NSTitlebarAccessoryViewController) -> Bool {
|
||||||
if childViewController.identifier == nil {
|
if childViewController.identifier == nil {
|
||||||
// The good case
|
// The good case
|
||||||
|
|
@ -283,6 +290,12 @@ class TerminalWindow: NSWindow {
|
||||||
// Whenever we change the window title we must also update our
|
// Whenever we change the window title we must also update our
|
||||||
// tab title if we're using custom fonts.
|
// tab title if we're using custom fonts.
|
||||||
tab.attributedTitle = attributedTitle
|
tab.attributedTitle = attributedTitle
|
||||||
|
/// We also needs to update this here, just in case
|
||||||
|
/// the value is not what we want
|
||||||
|
///
|
||||||
|
/// Check ``titlebarFont`` down below
|
||||||
|
/// to see why we need to check `hasMoreThanOneTabs` here
|
||||||
|
titlebarTextField?.usesSingleLineMode = !hasMoreThanOneTabs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -292,7 +305,12 @@ class TerminalWindow: NSWindow {
|
||||||
let font = titlebarFont ?? NSFont.titleBarFont(ofSize: NSFont.systemFontSize)
|
let font = titlebarFont ?? NSFont.titleBarFont(ofSize: NSFont.systemFontSize)
|
||||||
|
|
||||||
titlebarTextField?.font = font
|
titlebarTextField?.font = font
|
||||||
titlebarTextField?.usesSingleLineMode = true
|
/// We check `hasMoreThanOneTabs` here because the system
|
||||||
|
/// may copy this setting to the tab’s text field at some point(e.g. entering/exiting fullscreen),
|
||||||
|
/// which can cause the title to be vertically misaligned (shifted downward).
|
||||||
|
///
|
||||||
|
/// This behaviour is the opposite of what happens in the title bar’s text field, which is quite odd...
|
||||||
|
titlebarTextField?.usesSingleLineMode = !hasMoreThanOneTabs
|
||||||
tab.attributedTitle = attributedTitle
|
tab.attributedTitle = attributedTitle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue