From 8d8821004ecf288d6d97fe019df72558e088da2f Mon Sep 17 00:00:00 2001 From: Xiangbao Meng <134181853+bo2themax@users.noreply.github.com> Date: Sun, 12 Oct 2025 22:04:18 +0200 Subject: [PATCH] macOS: fix title misalignment in tabs (#9168) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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-0f2a7a6f342a --- .../Window Styles/TerminalWindow.swift | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/macos/Sources/Features/Terminal/Window Styles/TerminalWindow.swift b/macos/Sources/Features/Terminal/Window Styles/TerminalWindow.swift index 8249c6cf7..16fcf227f 100644 --- a/macos/Sources/Features/Terminal/Window Styles/TerminalWindow.swift +++ b/macos/Sources/Features/Terminal/Window Styles/TerminalWindow.swift @@ -205,9 +205,16 @@ class TerminalWindow: NSWindow { /// Returns true if there is a tab bar visible on this window. var hasTabBar: Bool { + // TODO: use titlebarView to find it instead 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 { if childViewController.identifier == nil { // The good case @@ -321,6 +328,12 @@ class TerminalWindow: NSWindow { // Whenever we change the window title we must also update our // tab title if we're using custom fonts. 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 } } @@ -330,7 +343,12 @@ class TerminalWindow: NSWindow { let font = titlebarFont ?? NSFont.titleBarFont(ofSize: NSFont.systemFontSize) 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 } }