From 41c872c1f4116b344e20985f1c41f604acc0cdd6 Mon Sep 17 00:00:00 2001 From: Lukas <134181853+bo2themax@users.noreply.github.com> Date: Fri, 10 Apr 2026 13:57:09 +0200 Subject: [PATCH] macOS: fix tab title editor frame update during winding resizing --- macos/Sources/Helpers/TabTitleEditor.swift | 30 ++++++++-------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/macos/Sources/Helpers/TabTitleEditor.swift b/macos/Sources/Helpers/TabTitleEditor.swift index 3e04d73c1..1c114a2a5 100644 --- a/macos/Sources/Helpers/TabTitleEditor.swift +++ b/macos/Sources/Helpers/TabTitleEditor.swift @@ -158,10 +158,8 @@ final class TabTitleEditor: NSObject, NSTextFieldDelegate { // Build the editor using title text and style derived from the tab's existing label. let editedTitle = delegate?.tabTitleEditor(self, titleFor: targetWindow) ?? targetWindow.title let sourceLabel = sourceTabTitleLabel(from: tabState.labels.map(\.label), matching: editedTitle) - let editorFrame = tabTitleEditorFrame(for: tabButton, sourceLabel: sourceLabel) - guard editorFrame.width >= 20, editorFrame.height >= 14 else { return false } - let editor = NSTextField(frame: editorFrame) + let editor = NSTextField(frame: .zero) editor.delegate = self editor.stringValue = editedTitle editor.alignment = sourceLabel?.alignment ?? .center @@ -193,6 +191,15 @@ final class TabTitleEditor: NSObject, NSTextFieldDelegate { tabButton.layoutSubtreeIfNeeded() tabButton.displayIfNeeded() tabButton.addSubview(editor) + editor.translatesAutoresizingMaskIntoConstraints = false + let horizontalInset: CGFloat = 6 + let editorHeight = sourceLabel?.bounds.height ?? tabButton.bounds.height + NSLayoutConstraint.activate([ + editor.centerYAnchor.constraint(equalTo: tabButton.centerYAnchor), + editor.leadingAnchor.constraint(equalTo: tabButton.leadingAnchor, constant: horizontalInset), + editor.trailingAnchor.constraint(equalTo: tabButton.trailingAnchor, constant: -horizontalInset), + editor.heightAnchor.constraint(equalToConstant: editorHeight), + ]) CATransaction.commit() // Focus after insertion so AppKit has created the field editor for this text field. @@ -256,23 +263,6 @@ final class TabTitleEditor: NSObject, NSTextFieldDelegate { delegate?.tabTitleEditor(self, didFinishEditing: targetWindow) } - /// Chooses an editor frame that aligns with the tab title within the tab button. - private func tabTitleEditorFrame(for tabButton: NSView, sourceLabel: NSTextField?) -> NSRect { - let bounds = tabButton.bounds - let horizontalInset: CGFloat = 6 - var frame = bounds.insetBy(dx: horizontalInset, dy: 0) - - if let sourceLabel { - let labelFrame = tabButton.convert(sourceLabel.bounds, from: sourceLabel) - /// The `labelFrame.minY` value changes unexpectedly after double clicking selected text, - /// I don't know exactly why, but `tabButton.bounds` appears stable enough to calculate the correct position reliably. - frame.origin.y = bounds.midY - labelFrame.height * 0.5 - frame.size.height = labelFrame.height - } - - return frame.integral - } - /// Selects the best title label candidate from private tab button subviews. private func sourceTabTitleLabel(from labels: [NSTextField], matching title: String) -> NSTextField? { let expected = title.trimmingCharacters(in: .whitespacesAndNewlines)