From 15ca32a5c9fd6b2b568b73653d6a0dd9c29f001d Mon Sep 17 00:00:00 2001 From: Joshua Park Date: Thu, 26 Nov 2026 21:09:42 -0500 Subject: [PATCH 1/3] fix(split-view): keep the sidebar's controls, tighten the chips, centre the divider on double-click --- docs/native-window.md | 2 +- native/ClairUI/AnchorResolver.swift | 16 +++- .../BrowserWindowController+Split.swift | 36 ++++++++ native/ClairUI/BrowserWindowController.swift | 14 +-- native/ClairUI/BrowserWindowModel.swift | 11 ++- native/ClairUI/PageToolbar.swift | 35 +++++--- native/ClairUI/SidebarView.swift | 65 +++++++++----- native/ClairUI/SplitViews.swift | 85 +++++++++++++++---- native/ClairUI/ToolbarPreference.swift | 18 ++-- native/ClairUITests/SplitTests.swift | 32 ++++++- native/ClairUITests/ToolbarTests.swift | 33 +++++-- openspec/specs/extensions/spec.md | 4 + openspec/specs/sidebar/spec.md | 10 +-- openspec/specs/split-view/spec.md | 21 +++-- tests/probe/README.md | 2 +- tests/probe/tools/mouse.swift | 26 +++--- 16 files changed, 315 insertions(+), 95 deletions(-) diff --git a/docs/native-window.md b/docs/native-window.md index 44feddd..eab5c04 100644 --- a/docs/native-window.md +++ b/docs/native-window.md @@ -84,7 +84,7 @@ The `add-link-rules` change's `design.md` (`openspec/changes/archive/2026-11-15- The browser controls show in one of two places, chosen by the `ClairShowsToolbar` preference (`ToolbarPreference`, on by default): a toolbar across the top of the card, or the sidebar's top row and URL field. The `add-page-toolbar` change's `design.md` (D1–D9) has the reasoning. -- **One rule decides where the controls show (D1).** `PageHeaderPolicy` takes the preference and the window's pane count, always 1 for now. Each pane shows a header while the preference is on or there's more than one pane, and the sidebar shows its controls only while no pane shows one. `BrowserWindowModel` exposes the result as `showsPageHeader` and `sidebarShowsControls`, and views read only those two. Split view will change the pane count and nothing else. +- **One rule decides where the controls show (D1).** `PageHeaderPolicy` takes the preference and the window's pane count, always 1 for now. Each pane shows a header while the preference is on or there's more than one pane. The sidebar keeps its top row, URL field and pinned extensions while the preference is off, a split included, as in Arc, so it doesn't shift; only back, forward and reload leave it while a pane shows a header. `BrowserWindowModel` exposes the result as `showsPageHeader`, `sidebarShowsControls` and `sidebarShowsNavigation`. While a split shows the controls in both places, `bubblesInSidebar` says which the user used last, and bubbles, popups and the Site Control Center attach there. - **The toolbar is a page header inside the card (D2).** `PageToolbar`, a SwiftUI view, sits in `PageCardView`'s container at the top of the card, with a 1 pt line over the page's top row. The page, the still, infobars, DevTools and the drag strip lie below it. `PageCardView.contentTop` gives that offset, and find and the notice popup are placed from it (D7). Page full screen hides the toolbar. - **A Peek covers it (D3).** Being in the container, the toolbar shrinks and washes with the parent page, and the click catcher closes the Peek. The Peek has its own `PageToolbar` with `.peek` content: back, forward, reload and the host, acting on the Peek's page. - **The same controls, moved (D4).** The toolbar reuses the sidebar's buttons and identifiers (`clair.hideSidebar`, `clair.back`, `clair.forward`, `clair.reload`, `clair.urlField`, `clair.copyURL`, `clair.siteControls`, `clair.extensionAction`). The toolbar is `clair.toolbar` and the Peek's `clair.peekToolbar`. `ToolbarArrangement` places them: Arc's leading slots, a 36 pt trailing pitch, the host centred on the card, and, in a narrow card, extensions and then reload with the link icon left out before the host truncates. `ToolbarLayout` lays them out from it. Every toolbar button is an `IconButton` at Arc's 32 × 24 (`IconButtonSize.toolbarHeight`), the link icon 22 × 24, with Arc's glyph sizes (`IconButtonSize.toolbarGlyph` and the other `toolbar…Glyph` sizes: 14 pt for the toggle, back, forward and reload, smaller than the sidebar's 16, and 12 for the link); a pinned extension is a `ToolbarExtensionButton`, which wraps one with the extension's menu, badge and anchor. The toolbar's blank areas move and zoom the window through `TitleBarArea`, whatever the page-top drag setting. diff --git a/native/ClairUI/AnchorResolver.swift b/native/ClairUI/AnchorResolver.swift index 67be648..7cfa479 100644 --- a/native/ClairUI/AnchorResolver.swift +++ b/native/ClairUI/AnchorResolver.swift @@ -15,7 +15,8 @@ enum AnchorControl: Hashable { } /// Where a Chromium bubble attaches (design D7): below its control in the -/// toolbar while the toolbar shows (add-page-toolbar D6); else to its control +/// toolbar while the toolbar shows (add-page-toolbar D6), unless the user +/// last used the sidebar's while a split shows both; else to its control /// in the sidebar while the sidebar is shown in place, or else to the card's /// top-leading corner. A revealed sidebar slides away when the pointer /// leaves, which would orphan a bubble, so it never anchors one. @@ -28,15 +29,26 @@ struct AnchorResolver { var sidebarInPlace: Bool /// The controls' frames, in window coordinates (origin at the bottom left). var controls: [AnchorControl: CGRect] - /// The card's frame, in window coordinates. + /// The card's frame, in window coordinates: the focused pane's in a split. var card: CGRect /// Whether the toolbar shows above the page: not while a page is in full /// screen. var toolbarShown = false /// The toolbar's controls' frames, in window coordinates. var toolbarControls: [AnchorControl: CGRect] = [:] + /// Whether the sidebar's controls come first: a split with the toolbar off + /// shows them in both, and the user last used the sidebar's. + var prefersSidebar = false + + /// Whether bubbles attach to the sidebar's controls before the toolbar's. + var anchorsInSidebar: Bool { prefersSidebar && sidebarInPlace } func anchor(for kind: AnchorKind, indicator: TabIndicators, extensionID: String?) -> BubbleAnchor { + if anchorsInSidebar, + let rect = controlRect(for: kind, indicator: indicator, extensionID: extensionID, in: controls) + { + return BubbleAnchor(rect: rect, edge: .trailing) + } if toolbarShown, let rect = controlRect(for: kind, indicator: indicator, extensionID: extensionID, in: toolbarControls) { diff --git a/native/ClairUI/BrowserWindowController+Split.swift b/native/ClairUI/BrowserWindowController+Split.swift index e7950c3..b350af9 100644 --- a/native/ClairUI/BrowserWindowController+Split.swift +++ b/native/ClairUI/BrowserWindowController+Split.swift @@ -13,6 +13,9 @@ extension BrowserWindowController: SplitActions { rootView.splitDivider.onDrag = { [weak self] x, done in self?.dividerMoved(to: x, done: done) } + rootView.splitDivider.onDoubleClick = { [weak self] in + self?.centreDivider() + } for (index, card) in [rootView.card, rootView.secondCard].enumerated() { card.onHover = { [weak model] inside in guard let model else { return } @@ -100,6 +103,7 @@ extension BrowserWindowController: SplitActions { /// The divider snaps to equal panes near the centre as it moves, with /// the trackpad's alignment feedback, and the ratio it's let go at sticks. private func dividerMoved(to x: CGFloat, done: Bool) { + splitRatioAnimator.stop() guard let split = model.shownSplit else { return } let width = rootView.pageArea.width let current = model.liveRatio(of: split) ?? split.ratio @@ -114,6 +118,38 @@ extension BrowserWindowController: SplitActions { } } + /// Double-clicking the divider slides it to the centre, with the + /// sidebar's spring, and keeps equal panes. + func centreDivider() { + guard let split = model.shownSplit else { return } + let current = model.liveRatio(of: split) ?? split.ratio + guard current != 0.5 else { return } + let finish = { [weak self] in + guard let self else { return } + self.model.liveSplitPanes = split.paneIDs + self.model.liveSplitRatio = 0.5 + self.browser?.setSplitRatio(0.5, of: split.leadingID) + } + guard rootView.window?.isVisible == true, !NSWorkspace.shared.accessibilityDisplayShouldReduceMotion else { + finish() + return + } + splitRatioAnimator.animate(in: rootView, from: current, to: 0.5) { [weak self] ratio, done in + // Another split, or none, ends it where it is. + guard let self, self.model.shownSplit?.paneIDs == split.paneIDs else { return false } + if done { + finish() + } else { + self.model.liveSplitPanes = split.paneIDs + self.model.liveSplitRatio = ratio + } + // Lay out now rather than on the next pass, so the pages resize in step. + self.rootView.needsLayout = true + self.rootView.layoutSubtreeIfNeeded() + return true + } + } + /// Lets go of the dragged ratio once the engine reports it, or once /// the window shows another split or none. func settleSplitRatio() { diff --git a/native/ClairUI/BrowserWindowController.swift b/native/ClairUI/BrowserWindowController.swift index d221d18..a8f5fc9 100644 --- a/native/ClairUI/BrowserWindowController.swift +++ b/native/ClairUI/BrowserWindowController.swift @@ -45,6 +45,8 @@ final class BrowserWindowController: NSObject, ClairWindow, SidebarActions, Over /// The pane whose header reported `toolbarFrames`. private var toolbarFramesPane = 0 private var extensionPopup: ExtensionPopupWindow? + /// Centres a split's divider when it's double-clicked. + let splitRatioAnimator = SplitRatioAnimator() /// The window's dialogs (add-clair-dialogs D1), for every dialog on it. private(set) lazy var dialogs = ClairDialogPresenter(window: window) private lazy var extensionPrompts = ExtensionPromptSheets(dialogs: dialogs) { [weak self] promptID, accepted in @@ -896,8 +898,8 @@ final class BrowserWindowController: NSObject, ClairWindow, SidebarActions, Over return AnchorResolver( sidebarInPlace: model.sidebar.isShownInPlace && !model.isPageFullscreen && !isWindowFullscreen, controls: controls, - card: rootView.convert(rootView.card.frame, to: nil), - toolbarShown: isToolbarShown, toolbarControls: toolbarControls) + card: rootView.convert(rootView.focusedCard.frame, to: nil), + toolbarShown: isToolbarShown, toolbarControls: toolbarControls, prefersSidebar: model.bubblesInSidebar) } /// Whether the toolbar shows above the page: not while a page is in full @@ -919,10 +921,12 @@ final class BrowserWindowController: NSObject, ClairWindow, SidebarActions, Over let anchorRect = self.anchor(for: anchor, indicator: [], extensionID: extensionID).rect let name = model.extensionActions.first { $0.extensionID == extensionID }?.name ?? "" // While the toolbar shows, every popup opens at the same place over it, - // as in Arc; its tile still closes it (add-page-toolbar D6). + // the focused pane's in a split, as in Arc; its tile still closes it + // (add-page-toolbar D6). + let resolver = anchorResolver var placement = ExtensionPopupWindow.Placement.besideAnchor - if isToolbarShown { - let card = rootView.convert(rootView.card.frame, to: nil) + if isToolbarShown && !resolver.anchorsInSidebar { + let card = resolver.card placement = .topTrailing(NSPoint(x: card.maxX - ExtensionPopupWindow.toolbarInset, y: card.maxY)) } let popup = ExtensionPopupWindow( diff --git a/native/ClairUI/BrowserWindowModel.swift b/native/ClairUI/BrowserWindowModel.swift index 62c8add..6154050 100644 --- a/native/ClairUI/BrowserWindowModel.swift +++ b/native/ClairUI/BrowserWindowModel.swift @@ -214,8 +214,11 @@ final class BrowserWindowModel { /// Whether the page shows its header, the toolbar. Views read this, not /// the preference. var showsPageHeader: Bool { headerPolicy.panesShowHeader } - /// Whether the sidebar shows the browser controls. + /// Whether the sidebar shows its full top row, the URL field and the + /// pinned extensions. var sidebarShowsControls: Bool { headerPolicy.sidebarShowsControls } + /// Whether the sidebar's top row shows back, forward and reload. + var sidebarShowsNavigation: Bool { headerPolicy.sidebarShowsNavigation } /// The Peek the card shows over its parent, if any (add-peek D4). var shownPeek: TabListLogic.ShownPeek? @@ -297,6 +300,12 @@ final class BrowserWindowModel { var isPageFullscreen = false var isSiteControlCenterOpen = false var isDownloadsListOpen = false + /// Whether the user last used the sidebar's controls rather than a pane + /// header's, while both show them: a split with the toolbar off. + var usedSidebarControls = false + /// Whether Chromium's bubbles, extension popups and the Site Control + /// Center attach to the sidebar's controls rather than the page header's. + var bubblesInSidebar: Bool { sidebarShowsControls && (!showsPageHeader || usedSidebarControls) } /// A revealed sidebar stays revealed while one of its popovers is open /// (arc-site-control-center design D8). var isSidebarPopoverOpen: Bool { isSiteControlCenterOpen || isDownloadsListOpen } diff --git a/native/ClairUI/PageToolbar.swift b/native/ClairUI/PageToolbar.swift index e6f3e78..b587acc 100644 --- a/native/ClairUI/PageToolbar.swift +++ b/native/ClairUI/PageToolbar.swift @@ -14,30 +14,31 @@ enum PageHeaderContent: Equatable { case tab /// A Peek's: back, forward, reload, the link icon and the host. case peek - /// A split's pane's header: the sidebar toggle in the leading pane, back, - /// forward, the link icon, the host and ×; with `expanded`, while the pane - /// is focused or under the pointer, also reload, the split button, site - /// controls, pinned extensions and indicators. - case pane(leading: Bool, expanded: Bool) + /// A split's pane's header: the sidebar toggle with `toggle` (the leading + /// pane's, while the toolbar preference is on), back, forward, the link + /// icon, the host and ×; with `expanded`, while the pane is focused or + /// under the pointer, also reload, the split button, site controls, pinned + /// extensions and indicators. + case pane(leading: Bool, toggle: Bool, expanded: Bool) /// The leading controls that always show before reload. var leadingCount: Int { switch self { case .tab: 3 case .peek: 2 - case .pane(let leading, _): leading ? 3 : 2 + case .pane(_, let toggle, _): toggle ? 3 : 2 } } var showsSidebarToggle: Bool { leadingCount == 3 } var showsReload: Bool { - if case .pane(_, let expanded) = self { return expanded } + if case .pane(_, _, let expanded) = self { return expanded } return true } private var showsAll: Bool { switch self { case .tab: true case .peek: false - case .pane(_, let expanded): expanded + case .pane(_, _, let expanded): expanded } } var showsSiteControls: Bool { showsAll } @@ -58,7 +59,7 @@ enum PageHeaderContent: Equatable { switch self { case .tab: "clair.toolbar" case .peek: "clair.peekToolbar" - case .pane(let leading, _): "clair.paneToolbar.\(leading ? 0 : 1)" + case .pane(let leading, _, _): "clair.paneToolbar.\(leading ? 0 : 1)" } } } @@ -111,7 +112,9 @@ struct PageToolbar: View { case .peek: return .peek case .pane(let index): guard let split = model.shownSplit else { return .tab } - return .pane(leading: index == 0, expanded: split.focusedIndex == index || model.hoveredPane == index) + return .pane( + leading: index == 0, toggle: model.headerPolicy.togglePane == index, + expanded: split.focusedIndex == index || model.hoveredPane == index) } } @@ -127,10 +130,12 @@ struct PageToolbar: View { return split.focusedIndex != index } - /// Runs `action` on the pane's tab: the pane is focused first. + /// Runs `action` on the pane's tab: the pane is focused first, and the + /// bubble it opens attaches to the header, not the sidebar. private func onPane(_ action: @escaping () -> Void) -> () -> Void { { [weak actions] in if isOtherPane, let paneTabID { actions?.focusPane(paneTabID) } + model.usedSidebarControls = false action() } } @@ -382,8 +387,12 @@ struct PageToolbar: View { // A click while the popover is open only closes it (arc-site-control-center // design D2). .allowsHitTesting(!model.isSiteControlCenterOpen) - // Only the focused pane's button holds the popover (add-split-view D9). - .popover(isPresented: isOtherPane ? .constant(false) : $model.isSiteControlCenterOpen, arrowEdge: .bottom) { + // Only the focused pane's button holds the popover (add-split-view D9), + // unless it was opened from the sidebar's URL field. + .popover( + isPresented: isOtherPane || model.bubblesInSidebar ? .constant(false) : $model.isSiteControlCenterOpen, + arrowEdge: .bottom + ) { SiteControlCenter(model: model, actions: actions) { model.isSiteControlCenterOpen = false } } .anchorFrame(.siteControls) diff --git a/native/ClairUI/SidebarView.swift b/native/ClairUI/SidebarView.swift index 1a743a9..4487dd1 100644 --- a/native/ClairUI/SidebarView.swift +++ b/native/ClairUI/SidebarView.swift @@ -140,11 +140,12 @@ struct SidebarView: View { .background { TitleBarArea { actions?.titleBarDoubleClicked() } } // The New Space form takes the URL field's place too, as in Arc. While // the toolbar shows, the field and the extensions are in it - // (add-page-toolbar D5). + // (add-page-toolbar D5); a split's pane headers leave them here, as + // in Arc. if model.newSpaceForm == nil && model.sidebarShowsControls { URLField( model: model, actions: actions, - showsButtons: (isHovered && model.isWindowKey) || model.isSiteControlCenterOpen) + showsButtons: (isHovered && model.isWindowKey) || (model.isSiteControlCenterOpen && model.bubblesInSidebar)) .padding(.horizontal, 8) .padding(.top, 6) } @@ -350,6 +351,9 @@ struct TopRow: View { // While the toolbar shows, the row keeps only the window controls' room, // at its height, so they stay at Arc's place (add-page-toolbar D5). let isCompact = model.sidebarShowsControls && controls.hasCompactTopRow(width: model.sidebar.width) + // A split's pane headers hold back, forward and reload; the row keeps its + // height and the hide-sidebar button, as in Arc. + let showsNavigation = model.sidebarShowsNavigation let size = isCompact ? IconButtonSize.small : IconButtonSize.regular let back = IconButton( systemImage: "arrow.left", help: "Go back", shortcut: ["⌘", "["], isEnabled: model.canGoBack, size: size @@ -380,8 +384,10 @@ struct TopRow: View { } else if isCompact { HStack(spacing: 0) { Spacer(minLength: 0) - back - forward + if showsNavigation { + back + forward + } IconMenu(help: "More options", size: IconButtonSize.small) { Group { if isLoading { @@ -413,24 +419,26 @@ struct TopRow: View { ) { actions?.toggleSidebar() } .accessibilityIdentifier("clair.hideSidebar") Spacer(minLength: 0) - HStack(spacing: Self.gap) { - back - forward - IconButton( - help: isLoading ? "Stop loading this page" : "Reload this page", - shortcut: isLoading ? ["esc"] : ["⌘", "R"], isEnabled: model.canReload && reloadStop.isEnabled - ) { - actions?.reloadOrStop() - } label: { - // Arc crossfades the two glyphs in about 100 ms. - ZStack { - SymbolGlyph(systemImage: "arrow.clockwise").opacity(isLoading ? 0 : 1) - SymbolGlyph(systemImage: "xmark").opacity(isLoading ? 1 : 0) + if showsNavigation { + HStack(spacing: Self.gap) { + back + forward + IconButton( + help: isLoading ? "Stop loading this page" : "Reload this page", + shortcut: isLoading ? ["esc"] : ["⌘", "R"], isEnabled: model.canReload && reloadStop.isEnabled + ) { + actions?.reloadOrStop() + } label: { + // Arc crossfades the two glyphs in about 100 ms. + ZStack { + SymbolGlyph(systemImage: "arrow.clockwise").opacity(isLoading ? 0 : 1) + SymbolGlyph(systemImage: "xmark").opacity(isLoading ? 1 : 0) + } + .animation(reduceMotion ? nil : .easeInOut(duration: 0.1), value: isLoading) } - .animation(reduceMotion ? nil : .easeInOut(duration: 0.1), value: isLoading) + .onHover { actions?.reloadButtonHovered($0) } + .accessibilityIdentifier("clair.reload") } - .onHover { actions?.reloadButtonHovered($0) } - .accessibilityIdentifier("clair.reload") } } .padding(.trailing, Self.trailing) @@ -458,6 +466,12 @@ struct URLField: View { /// Arc's URL-field buttons: 28 pt, side by side. static let buttonSize = IconButtonSize.small + /// Whether the Site Control Center shows from this field: not while it + /// shows from a split's pane header. + private var siteControlCenterShown: Binding { + Binding { model.isSiteControlCenterOpen && model.bubblesInSidebar } set: { model.isSiteControlCenterOpen = $0 } + } + static let indicatorSymbols: [(TabIndicators, String, String)] = [ (.camera, "video.fill", "Camera"), (.microphone, "mic.fill", "Microphone"), @@ -508,6 +522,7 @@ struct URLField: View { ForEach(Self.indicatorSymbols, id: \.0.rawValue) { indicator, symbol, label in if tab?.indicators.contains(indicator) == true { Button { + model.usedSidebarControls = true actions?.showSiteControls(indicator: indicator) } label: { Image(systemName: symbol) @@ -535,6 +550,7 @@ struct URLField: View { systemImage: "slider.horizontal.2.square", help: "Site Control Center", glyphSize: URLFieldButton.siteControlsGlyphSize, glyphWeight: .regular ) { + model.usedSidebarControls = true model.isSiteControlCenterOpen = true } // A click while the popover is open only closes it: the transient @@ -554,7 +570,7 @@ struct URLField: View { .frame(width: Self.buttonSize, height: Self.buttonSize) .allowsHitTesting(false) .accessibilityHidden(true) - .popover(isPresented: $model.isSiteControlCenterOpen, arrowEdge: .bottom) { + .popover(isPresented: siteControlCenterShown, arrowEdge: .bottom) { SiteControlCenter(model: model, actions: actions) { model.isSiteControlCenterOpen = false } } .padding(.trailing, 5) @@ -608,8 +624,11 @@ struct ToolsRow: View { PinnedExtensionTile( action: action, contextMenu: { actions?.contextMenu(forExtension: action.extensionID) } - ) { actions?.runExtension(action.extensionID, pinned: true) } - .anchorFrame(.extensionAction(action.extensionID)) + ) { + model.usedSidebarControls = true + actions?.runExtension(action.extensionID, pinned: true) + } + .anchorFrame(.extensionAction(action.extensionID)) } } } diff --git a/native/ClairUI/SplitViews.swift b/native/ClairUI/SplitViews.swift index b17bdc5..816a6f4 100644 --- a/native/ClairUI/SplitViews.swift +++ b/native/ClairUI/SplitViews.swift @@ -8,14 +8,16 @@ import SwiftUI // MARK: The divider (add-split-view design D3) -/// The gap between a split's panes: a grabber, the resize pointer, and a drag -/// that resizes the panes, reporting the divider's centre in the page area. -/// The grabber stays faint until the pointer is over the divider or drags -/// it. +/// The gap between a split's panes: a grabber, the resize pointer, a drag +/// that resizes the panes, reporting the divider's centre in the page area, +/// and a double-click that centres it. The grabber stays faint until the +/// pointer is over the divider or drags it. final class SplitDividerView: NSView { /// The divider moved to `x`, from the page area's leading edge; `done` on /// the drag's last step. var onDrag: ((CGFloat, _ done: Bool) -> Void)? + /// The divider was double-clicked. + var onDoubleClick: (() -> Void)? /// The page area's leading edge, in the divider's superview. var areaMinX: CGFloat = 0 @@ -24,12 +26,14 @@ final class SplitDividerView: NSView { private var isHovered = false private var isDragging = false + /// The grabber under the pointer; it rests at about the colour it always + /// had, and darkens more under the pointer. static let grabberColor = NSColor(name: "clair.splitGrabber") { appearance in - appearance.isDark ? NSColor(white: 1, alpha: 0.28) : NSColor(white: 0, alpha: 0.22) + appearance.isDark ? NSColor(white: 1, alpha: 0.4) : NSColor(white: 0, alpha: 0.3) } - static let grabberSize = CGSize(width: 4, height: 32) + static let grabberSize = CGSize(width: 3, height: 32) /// The grabber's opacity while the pointer is elsewhere, and under it. - static let restingAlpha: CGFloat = 0.35 + static let restingAlpha: CGFloat = 0.25 static let activeAlpha: CGFloat = 1 override init(frame: NSRect) { @@ -83,6 +87,12 @@ final class SplitDividerView: NSView { } override func mouseDown(with event: NSEvent) { + if event.clickCount == 2 { + // The second click centres the divider; it doesn't drag it. + isDragging = false + onDoubleClick?() + return + } let point = convert(event.locationInWindow, from: nil) dragOffset = point.x - bounds.midX isDragging = true @@ -90,12 +100,16 @@ final class SplitDividerView: NSView { } override func mouseDragged(with event: NSEvent) { + guard isDragging else { return } report(event, done: false) } override func mouseUp(with event: NSEvent) { + let wasDragging = isDragging isDragging = false - report(event, done: true) + if wasDragging { + report(event, done: true) + } isHovered = bounds.contains(convert(event.locationInWindow, from: nil)) updateGrabber() } @@ -118,6 +132,42 @@ final class SplitDividerView: NSView { } } +/// Moves a split's divider to a ratio with the sidebar's spring, a frame at +/// a time. `onStep` takes each ratio, `done` with the last, and returns +/// whether to go on. +final class SplitRatioAnimator: NSObject { + private var spring = SpringValue(0.5) + private var link: CADisplayLink? + private var onStep: ((CGFloat, _ done: Bool) -> Bool)? + + func animate( + in view: NSView, from start: CGFloat, to target: CGFloat, onStep: @escaping (CGFloat, _ done: Bool) -> Bool + ) { + spring = SpringValue(start) + spring.animate(to: target, at: CACurrentMediaTime()) + self.onStep = onStep + guard link == nil else { return } + let link = view.displayLink(target: self, selector: #selector(step)) + link.add(to: .main, forMode: .common) + self.link = link + } + + /// Stops where it is, as when the user drags the divider. + func stop() { + link?.invalidate() + link = nil + onStep = nil + } + + @objc private func step(_ link: CADisplayLink) { + let moving = spring.step(at: CACurrentMediaTime()) + let goesOn = onStep?(moving ? spring.value : spring.target, !moving) ?? false + if !moving || !goesOn { + stop() + } + } +} + // MARK: Dragging a tab onto the page (D8) /// Takes a sidebar row or tile dragged over the page: the half or pane under @@ -408,14 +458,19 @@ struct SplitRow: View { var body: some View { HStack(spacing: Self.chipGap) { ForEach(Array(pages.enumerated()), id: \.offset) { index, page in - if index > 0 { - // Kept, clear, while selected, so the chips don't move, as in Arc. - Rectangle() - .fill(PinFill.divider) - .frame(width: 1, height: 16) - .opacity(isActive ? 0 : 1) - } chip(page, index: index) + // The divider sits in the gap without taking room, so the chips + // stay as close as Arc's and don't move as it hides while + // selected. + .background(alignment: .leading) { + if index > 0 { + Rectangle() + .fill(PinFill.divider) + .frame(width: 1, height: 16) + .offset(x: -(Self.chipGap + 1) / 2) + .opacity(isActive ? 0 : 1) + } + } } if isHovered, let button { IconButton( diff --git a/native/ClairUI/ToolbarPreference.swift b/native/ClairUI/ToolbarPreference.swift index ad52870..5d34452 100644 --- a/native/ClairUI/ToolbarPreference.swift +++ b/native/ClairUI/ToolbarPreference.swift @@ -34,16 +34,22 @@ struct ToolbarPreference { struct PageHeaderPolicy: Equatable { /// Whether each pane shows a header above its page. let panesShowHeader: Bool - /// Whether the sidebar shows back, forward, reload, the URL field and the - /// pinned extensions: only while no pane shows a header. + /// Whether the sidebar shows its full top row with the hide-sidebar + /// button, the URL field and the pinned extensions: while the toolbar is + /// off, a split's pane headers included, as in Arc, so the sidebar doesn't + /// shift as the user moves between a split and other tabs. let sidebarShowsControls: Bool - /// The pane whose header leads with the sidebar toggle, if any pane shows - /// one: the leading pane. + /// Whether the sidebar's top row shows back, forward and reload: only while + /// no pane shows a header. + let sidebarShowsNavigation: Bool + /// The pane whose header leads with the sidebar toggle, if any: the + /// leading pane, while the sidebar's top row doesn't hold the toggle. let togglePane: Int? init(showsToolbar: Bool, paneCount: Int) { panesShowHeader = showsToolbar || paneCount > 1 - sidebarShowsControls = !panesShowHeader - togglePane = panesShowHeader ? 0 : nil + sidebarShowsControls = !showsToolbar + sidebarShowsNavigation = !panesShowHeader + togglePane = showsToolbar ? 0 : nil } } diff --git a/native/ClairUITests/SplitTests.swift b/native/ClairUITests/SplitTests.swift index 2540359..b2268d6 100644 --- a/native/ClairUITests/SplitTests.swift +++ b/native/ClairUITests/SplitTests.swift @@ -118,10 +118,13 @@ struct SplitLogicTests { } @Test func paneHeadersExpandWhileFocusedOrHovered() { - let leading = PageHeaderContent.pane(leading: true, expanded: false) + let leading = PageHeaderContent.pane(leading: true, toggle: true, expanded: false) #expect(leading.showsSidebarToggle && !leading.showsReload && !leading.showsSplitButton && leading.showsClose) #expect(leading.trailingFixedCount == 1) - let trailing = PageHeaderContent.pane(leading: false, expanded: true) + // With the toolbar off, the sidebar keeps the toggle. + let untoggled = PageHeaderContent.pane(leading: true, toggle: false, expanded: false) + #expect(!untoggled.showsSidebarToggle && untoggled.leadingCount == 2) + let trailing = PageHeaderContent.pane(leading: false, toggle: false, expanded: true) #expect(!trailing.showsSidebarToggle && trailing.showsReload && trailing.showsSplitButton) #expect(trailing.trailingFixedCount == 3) #expect(trailing.identifier == "clair.paneToolbar.1") @@ -392,6 +395,31 @@ struct SplitWindowTests { #expect(divider.grabberAlpha == SplitDividerView.restingAlpha) } + /// Double-clicking the divider centres it; the second click doesn't drag + /// it back to the pointer. + @Test func doubleClickingTheDividerCentresIt() throws { + browser.split(tab: mail.tabID, with: docs.tabID, side: .trailing) + let root = controller.rootView + root.frame = CGRect(x: 0, y: 0, width: 1400, height: 900) + root.layoutSubtreeIfNeeded() + let width = root.pageArea.width + let divider = root.splitDivider + divider.onDrag?(width / 2 - 150, true) + #expect((browser.host.tab(mail.tabID)?.splitRatio ?? 0.5) < 0.45) + let point = divider.convert(CGPoint(x: divider.bounds.midX, y: divider.bounds.midY), to: nil) + for count in [1, 2] { + for type in [NSEvent.EventType.leftMouseDown, .leftMouseUp] { + let event = try #require( + NSEvent.mouseEvent( + with: type, location: point, modifierFlags: [], timestamp: 0, windowNumber: 0, context: nil, + eventNumber: 0, clickCount: count, pressure: 1)) + if type == .leftMouseDown { divider.mouseDown(with: event) } else { divider.mouseUp(with: event) } + } + } + #expect(browser.host.tab(mail.tabID)?.splitRatio == 0.5) + #expect(controller.model.liveSplitRatio == 0.5) + } + @Test func theDividerKeepsTheRatioItsLetGoAt() { browser.split(tab: mail.tabID, with: docs.tabID, side: .trailing) let root = controller.rootView diff --git a/native/ClairUITests/ToolbarTests.swift b/native/ClairUITests/ToolbarTests.swift index 7e55b19..3a4a41e 100644 --- a/native/ClairUITests/ToolbarTests.swift +++ b/native/ClairUITests/ToolbarTests.swift @@ -56,16 +56,20 @@ struct ToolbarPreferenceTests { let policy = PageHeaderPolicy(showsToolbar: showsToolbar, paneCount: 1) #expect(policy.panesShowHeader == showsToolbar) #expect(policy.sidebarShowsControls == !showsToolbar) + #expect(policy.sidebarShowsNavigation == !showsToolbar) #expect(policy.togglePane == (showsToolbar ? 0 : nil)) } - /// Split view: every pane shows its header whatever the setting. + /// Split view: every pane shows its header whatever the setting. With the + /// toolbar off, the sidebar keeps its toggle, URL field and pinned + /// extensions, as in Arc, and only back, forward and reload leave it. @Test(arguments: [true, false]) func twoPanesAlwaysShowHeaders(showsToolbar: Bool) { let policy = PageHeaderPolicy(showsToolbar: showsToolbar, paneCount: 2) #expect(policy.panesShowHeader) - #expect(!policy.sidebarShowsControls) - #expect(policy.togglePane == 0) + #expect(policy.sidebarShowsControls == !showsToolbar) + #expect(!policy.sidebarShowsNavigation) + #expect(policy.togglePane == (showsToolbar ? 0 : nil)) } @Test func theModelFollowsThePolicy() { @@ -84,7 +88,11 @@ struct ToolbarPreferenceTests { // A split shows both panes' headers (add-split-view D9). browser.makeSplit(mail.tabID, with: news.tabID) #expect(model.paneCount == 2) - #expect(model.showsPageHeader && !model.sidebarShowsControls) + #expect(model.showsPageHeader && model.sidebarShowsControls && !model.sidebarShowsNavigation) + // Bubbles attach to the controls the user used last. + #expect(!model.bubblesInSidebar) + model.usedSidebarControls = true + #expect(model.bubblesInSidebar) } } @@ -247,7 +255,7 @@ struct ToolbarAnchorTests { let downloads = CGRect(x: 8, y: 9, width: 32, height: 32) let card = CGRect(x: 228, y: 10, width: 962, height: 780) - func resolver(sidebarInPlace: Bool, toolbarShown: Bool) -> AnchorResolver { + func resolver(sidebarInPlace: Bool, toolbarShown: Bool, prefersSidebar: Bool = false) -> AnchorResolver { AnchorResolver( sidebarInPlace: sidebarInPlace, controls: [.siteControls: sidebarSite, .downloads: downloads], @@ -256,7 +264,20 @@ struct ToolbarAnchorTests { .siteControls: toolbarSite, .indicator(TabIndicators.camera.rawValue): toolbarCamera, .extensionAction("pinned"): toolbarPinned, - ]) + ], + prefersSidebar: prefersSidebar) + } + + /// A split with the toolbar off shows the controls in the sidebar and the + /// pane headers: bubbles attach where the user clicked, while the sidebar + /// is in place. + @Test func theSidebarWinsWhenUsedLast() { + let used = resolver(sidebarInPlace: true, toolbarShown: true, prefersSidebar: true) + #expect(used.anchorsInSidebar) + #expect(used.anchor(for: .siteControls, indicator: [], extensionID: nil).rect == sidebarSite) + let revealed = resolver(sidebarInPlace: false, toolbarShown: true, prefersSidebar: true) + #expect(!revealed.anchorsInSidebar) + #expect(revealed.anchor(for: .siteControls, indicator: [], extensionID: nil).rect == toolbarSite) } /// With the sidebar shown, hidden, or revealed (never in place): below the diff --git a/openspec/specs/extensions/spec.md b/openspec/specs/extensions/spec.md index 93b8600..3403586 100644 --- a/openspec/specs/extensions/spec.md +++ b/openspec/specs/extensions/spec.md @@ -123,6 +123,10 @@ An extension's popup SHALL open in a small titled window whose only enabled cont - **WHEN** the toolbar is shown and the user clicks a pinned extension's tile whose action has a popup - **THEN** a window with a close button opens over the toolbar, its top-trailing corner at the card's top edge and 40 points in from the card's trailing edge, showing the whole popup page +#### Scenario: A popup from the trailing pane +- **WHEN** the window shows a split and the user clicks a pinned extension's tile in the trailing pane's header +- **THEN** the popup's window opens at the trailing pane's top-trailing corner, not the leading pane's + #### Scenario: Another extension from the toolbar - **WHEN** the toolbar is shown and the user opens a second pinned extension's popup, whose tile is further from the trailing edge - **THEN** its window's top-trailing corner is at the same place as the first's diff --git a/openspec/specs/sidebar/spec.md b/openspec/specs/sidebar/spec.md index 4a9ae7f..712cdd4 100644 --- a/openspec/specs/sidebar/spec.md +++ b/openspec/specs/sidebar/spec.md @@ -6,7 +6,7 @@ Defines the native window's sidebar: the browser controls it carries in place of ## Requirements ### Requirement: Navigation controls -The sidebar's top row SHALL hold, after the window controls, a button that hides the sidebar, then back, forward and reload. Back and forward SHALL be dimmed and inert when the active tab can't go that way. Reload SHALL become stop while the active tab loads. When the sidebar is too narrow for that row, as in Arc, the row SHALL hold back, forward and a menu offering reload (or stop) and Hide Sidebar. While the toolbar or a split's pane headers show, the row SHALL hold only the window controls. +The sidebar's top row SHALL hold, after the window controls, a button that hides the sidebar, then back, forward and reload. Back and forward SHALL be dimmed and inert when the active tab can't go that way. Reload SHALL become stop while the active tab loads. In a sidebar too narrow for it, as in Arc, the row SHALL hold back, forward and a menu offering reload (or stop) and Hide Sidebar. The toolbar SHALL take all but the window controls, and a split's pane headers back, forward and reload. #### Scenario: Going back - **WHEN** the user has followed a link in the active tab and clicks back @@ -26,7 +26,7 @@ The sidebar's top row SHALL hold, after the window controls, a button that hides #### Scenario: A split with the toolbar off - **WHEN** the toolbar is off and the window shows a split -- **THEN** the sidebar's top row shows only the window controls, and the hide-sidebar button, back, forward and reload are in the pane headers +- **THEN** the sidebar's top row shows the window controls and the hide-sidebar button where they were, and back, forward and reload are in the pane headers ### Requirement: Tooltips in Arc's wording The sidebar's controls SHALL have Clair's own tooltips, never the system's, in Arc's wording and with their shortcuts: "Hide sidebar" ("Show sidebar" while hidden, "Lock sidebar" while the hidden sidebar is revealed), "Go back", "Go forward", "Reload this page" or "Stop loading this page", "Copy URL", "Site Control Center", "Close tab" and "More options"; also "Downloads", "New" on the footer's plus, and a pinned extension's action title, or its name when that's empty. @@ -74,7 +74,7 @@ Resting the pointer on a tab row for about 2 seconds SHALL show a tooltip as `ta - **THEN** no tooltip shows the tab's title ### Requirement: URL field -Below the top row, the sidebar SHALL show the active tab's host without a leading `www.`, or its full URL for pages without a host such as `chrome://` pages and files, with a search icon and "Search or Enter URL…" for a new tab page. Clicking the field SHALL open the command bar on the current URL, and its context menu SHALL offer Copy URL. While the pointer is over the field, its background SHALL darken. While the toolbar or a split's pane headers show, the field SHALL be their hosts instead. +Below the top row, the sidebar SHALL show the active tab's host without a leading `www.`, or its full URL for pages without a host such as `chrome://` pages and files, with a search icon and "Search or Enter URL…" for a new tab page. Clicking the field SHALL open the command bar on the current URL, and its context menu SHALL offer Copy URL. While the pointer is over the field, its background SHALL darken. While the toolbar shows, the field SHALL be its host instead. #### Scenario: Web page - **WHEN** the active tab shows `https://news.ycombinator.com/item?id=1` @@ -97,8 +97,8 @@ Below the top row, the sidebar SHALL show the active tab's host without a leadin - **THEN** the sidebar shows no URL field, and the toolbar shows the host #### Scenario: A split with the toolbar off -- **WHEN** the toolbar is off and the window shows a split -- **THEN** the sidebar shows no URL field, and each pane's header shows its host +- **WHEN** the toolbar is off and the window shows a split with "Docs" focused +- **THEN** the sidebar's URL field shows "Docs"'s host where it was, and each pane's header shows its own host ### Requirement: URL field buttons While the toolbar is off and the pointer is anywhere over the key window's sidebar, the URL field's trailing end SHALL show a copy button and the site-controls button, fading in and out. While the toolbar shows, its buttons SHALL always show (`page-toolbar`). diff --git a/openspec/specs/split-view/spec.md b/openspec/specs/split-view/spec.md index 5407508..c21b243 100644 --- a/openspec/specs/split-view/spec.md +++ b/openspec/specs/split-view/spec.md @@ -47,15 +47,19 @@ While the page is split, the command bar SHALL open centred on the focused pane - **THEN** the command bar opens as near the pane's centre as it can while staying inside the window ### Requirement: Pane headers -While the page is split, each pane SHALL have a header, whatever the toolbar preference, laid out as the toolbar (`page-toolbar`). Each SHALL hold back, forward, the link icon, the host and a close button centred 21 points from its trailing edge. The leading pane's header SHALL also lead with the sidebar toggle. The focused pane's SHALL also show reload and, left of the close button and 36 points apart, the split button, site controls, pinned extensions and indicators, as in Arc. +While the page is split, each pane SHALL have a header, whatever the toolbar preference, laid out as the toolbar (`page-toolbar`). Each SHALL hold back, forward, the link icon, the host and × centred 21 points from its trailing edge. With the toolbar on, the leading pane's header SHALL also lead with the sidebar toggle. The focused pane's SHALL also show reload and, left of the close button and 36 points apart, the split button, site controls, pinned extensions and indicators, as in Arc. #### Scenario: Headers of a split -- **WHEN** the window shows a split with the trailing pane focused +- **WHEN** the toolbar preference is on and the window shows a split with the trailing pane focused - **THEN** the leading pane's header shows the sidebar toggle, back, forward, the link icon, its host and ×, and the trailing pane's shows back, forward, reload, the link icon, its host, the indicators, pinned extensions, site controls, the split button and × #### Scenario: Toolbar preference off - **WHEN** the toolbar preference is off and the user makes a split -- **THEN** both panes show headers, and the sidebar shows no back, forward, reload or URL field until the split ends +- **THEN** both panes show headers without the sidebar toggle, and the sidebar keeps its top row's height and hide-sidebar button, its URL field, showing the focused pane's URL, and its pinned extensions, as in Arc, so nothing in it moves; only back, forward and reload leave its top row until the split ends + +#### Scenario: Bubbles with the toolbar off +- **WHEN** the toolbar preference is off, the window shows a split, and the user clicks a pinned extension or the site-controls button in the sidebar +- **THEN** its popup or the Site Control Center opens beside the sidebar's control, as without a split; clicking one in the focused pane's header opens it there instead ### Requirement: Controls of the other pane While the pointer is over the pane that isn't focused, its header SHALL show its reload, split button, site-controls button, pinned extensions and indicators too, fading in and out, as Arc does near its toolbar. Clicking one of them SHALL focus that pane and act on its tab. @@ -85,12 +89,19 @@ A divider in the gap between the panes SHALL show the resize pointer and a faint #### Scenario: The grabber - **WHEN** the pointer moves over the divider -- **THEN** the grabber fades to its full colour, and back to faint once the pointer leaves +- **THEN** the grabber fades to a darker colour, and back to faint once the pointer leaves #### Scenario: Coming back to the split - **WHEN** the user resized a split, selects another tab and then selects the split again - **THEN** the split shows with the ratio it had +### Requirement: Centring the divider +Double-clicking the divider SHALL slide it to the centre, resizing the panes as it moves, and keep the panes equal. + +#### Scenario: Double-clicking the divider +- **WHEN** the user double-clicks the divider of a split whose leading pane is wider +- **THEN** the divider slides to the centre, the panes resize with it, and they stay equal + ### Requirement: Dragging a tab onto the page Dragging a Today tab, pinned tab or favorite over the page SHALL turn the drag into a portrait card with the tab's favicon and title, as in Arc. While the page isn't split, the half under the pointer SHALL become a translucent drop zone with an accent border, the page sliding to the other half, and moving across SHALL swap them. Dropping SHALL make a split with the tab in that half. @@ -272,7 +283,7 @@ Separate Tabs, in a pane's split menu, the split row's menu and View, SHALL end - **THEN** the sidebar lists "News" and then "Docs" where the split's row was, and the window shows "Docs" alone ### Requirement: The split row -In the sidebar, a split SHALL show as one row with a chip per tab, in pane order, each with the tab's favicon and title (or custom name), truncated to share the row, as in Arc. While the split isn't selected, a thin divider SHALL separate the chips. While it's selected, the row SHALL be highlighted and each chip SHALL show as its own grey pill, in the same place as before, as in Arc. +In the sidebar, a split SHALL show as one row with a chip per tab, in pane order, each with the tab's favicon and title (or custom name), truncated to share the row, as in Arc. The chips SHALL be about 3 points apart, as in Arc. While the split isn't selected, a thin divider SHALL separate them, in that gap. While it's selected, the row SHALL be highlighted and each chip SHALL show as its own grey pill, in the same place as before, as in Arc. #### Scenario: A split in Today - **WHEN** a Space has the Today tabs "Mail" and a split of "News" and "Docs" diff --git a/tests/probe/README.md b/tests/probe/README.md index 772cffe..36e8606 100644 --- a/tests/probe/README.md +++ b/tests/probe/README.md @@ -117,7 +117,7 @@ build/probe/bin/measure track build/probe/rec/peek/frames white 0 0 2400 2012 80 - `tools/` holds small Swift tools, compiled into `build/probe/bin/` on first use (or by `tools/build.sh`); each describes its arguments at the top: `windows` (window IDs and frames, by app name or process ID), `drag` (a drag - with real mouse events, in screen points), `mouse` (a real pointer move or + with real mouse events, in screen points), `mouse` (a real pointer move, double-click or click, in screen points), `cdp` (DevTools protocol commands for the test copy), `frames` (a movie's frames), `sheet` (a labelled contact sheet), `crop` (a pixel rectangle; `sips --cropOffset` diff --git a/tests/probe/tools/mouse.swift b/tests/probe/tools/mouse.swift index 30d1566..c992305 100644 --- a/tests/probe/tools/mouse.swift +++ b/tests/probe/tools/mouse.swift @@ -4,9 +4,10 @@ // mouse move // mouse click +// mouse doubleclick // // Moves the real pointer to a point in screen points (as `probe.sh send tree` -// prints frames), and clicks there with `click`. For when the probe's own +// prints frames), and clicks there with `click`, or twice with `doubleclick`. For when the probe's own // `hover` and `click` can't reach: they're relative to the app's first window, // which is a dialog while one shows, and a SwiftUI hover in a window that isn't // key (a sidebar row's close button behind a page's alert) didn't appear for @@ -19,8 +20,8 @@ import Foundation let arguments = Array(CommandLine.arguments.dropFirst()) let numbers = arguments.dropFirst().compactMap { Double($0) } -guard arguments.count == 3, ["move", "click"].contains(arguments[0]), numbers.count == 2 else { - FileHandle.standardError.write("usage: mouse move|click \n".data(using: .utf8)!) +guard arguments.count == 3, ["move", "click", "doubleclick"].contains(arguments[0]), numbers.count == 2 else { + FileHandle.standardError.write("usage: mouse move|click|doubleclick \n".data(using: .utf8)!) exit(2) } guard CGPreflightPostEventAccess() else { @@ -29,18 +30,23 @@ guard CGPreflightPostEventAccess() else { } let point = CGPoint(x: numbers[0], y: numbers[1]) -func post(_ type: CGEventType) { - CGEvent(mouseEventSource: nil, mouseType: type, mouseCursorPosition: point, mouseButton: .left)? - .post(tap: .cghidEventTap) +func post(_ type: CGEventType, clickCount: Int64 = 1) { + let event = CGEvent(mouseEventSource: nil, mouseType: type, mouseCursorPosition: point, mouseButton: .left) + event?.setIntegerValueField(.mouseEventClickState, value: clickCount) + event?.post(tap: .cghidEventTap) } // Two moves, so a view's hover sees the pointer arrive. post(.mouseMoved) usleep(150_000) post(.mouseMoved) -if arguments[0] == "click" { +if arguments[0] != "move" { usleep(300_000) - post(.leftMouseDown) - usleep(80_000) - post(.leftMouseUp) + // A double-click's second press and release carry a click count of 2. + for count in Int64(1)...(arguments[0] == "doubleclick" ? 2 : 1) { + post(.leftMouseDown, clickCount: count) + usleep(60_000) + post(.leftMouseUp, clickCount: count) + usleep(60_000) + } } From a6d04ff151592be52cb288024b08cabb5e6cdbbd Mon Sep 17 00:00:00 2001 From: Joshua Park Date: Thu, 26 Nov 2026 21:20:25 -0500 Subject: [PATCH 2/3] fix(split-view): drop reload from the compact menu in a split, stop the divider animation on close --- native/ClairUI/BrowserWindowController.swift | 5 ++++- native/ClairUI/SidebarView.swift | 15 +++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/native/ClairUI/BrowserWindowController.swift b/native/ClairUI/BrowserWindowController.swift index a8f5fc9..1ddd60b 100644 --- a/native/ClairUI/BrowserWindowController.swift +++ b/native/ClairUI/BrowserWindowController.swift @@ -373,13 +373,16 @@ final class BrowserWindowController: NSObject, ClairWindow, SidebarActions, Over } } - deinit { + isolated deinit { for observer in observers { NotificationCenter.default.removeObserver(observer) } if let flagsMonitor { NSEvent.removeMonitor(flagsMonitor) } + // A window closed while the divider centres suspends the display link + // rather than invalidating it, which would keep it and the animator. + splitRatioAnimator.stop() } // MARK: Dragging the window from the top of the page diff --git a/native/ClairUI/SidebarView.swift b/native/ClairUI/SidebarView.swift index 4487dd1..0d5fc4b 100644 --- a/native/ClairUI/SidebarView.swift +++ b/native/ClairUI/SidebarView.swift @@ -389,14 +389,17 @@ struct TopRow: View { forward } IconMenu(help: "More options", size: IconButtonSize.small) { - Group { - if isLoading { - Button("Stop") { actions?.reloadOrStop() }.keyboardShortcut(.escape, modifiers: []) - } else { - Button("Reload") { actions?.reloadOrStop() }.keyboardShortcut("r", modifiers: .command) + // A split's pane headers hold reload too. + if showsNavigation { + Group { + if isLoading { + Button("Stop") { actions?.reloadOrStop() }.keyboardShortcut(.escape, modifiers: []) + } else { + Button("Reload") { actions?.reloadOrStop() }.keyboardShortcut("r", modifiers: .command) + } } + .disabled(!model.canReload || !reloadStop.isEnabled) } - .disabled(!model.canReload || !reloadStop.isEnabled) Button("Hide Sidebar") { actions?.toggleSidebar() }.keyboardShortcut("s", modifiers: .command) } label: { SymbolGlyph(systemImage: "ellipsis") From 5b2313759d2f52ed51631b5a889c84a2f5d59f14 Mon Sep 17 00:00:00 2001 From: Joshua Park Date: Thu, 26 Nov 2026 21:57:50 -0500 Subject: [PATCH 3/3] fix(split-view): swap pane headers without fading, drop Hide Toolbar from them while it's off --- native/ClairUI/PageToolbar.swift | 30 +++++++++++++++++++++------- native/ClairUITests/SplitTests.swift | 10 ++++++++++ openspec/specs/page-toolbar/spec.md | 6 +++++- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/native/ClairUI/PageToolbar.swift b/native/ClairUI/PageToolbar.swift index b587acc..942da6a 100644 --- a/native/ClairUI/PageToolbar.swift +++ b/native/ClairUI/PageToolbar.swift @@ -244,6 +244,9 @@ struct PageToolbar: View { .toolbarRole(.trailingFixed(closeSlot)) } } + // Showing another split, or none, swaps the header at once: the fade is + // only for the controls of the split already shown. + .transaction(value: model.shownSplit?.paneIDs) { $0.animation = nil } // The other pane's controls fade in and out as the pointer comes and // goes, as Arc's do (add-split-view, "Controls of the other pane"). .animation(reduceMotion ? nil : .easeInOut(duration: 0.15), value: content) @@ -411,16 +414,29 @@ struct PageToolbar: View { /// The toolbar's context menu: Copy URL and Hide Toolbar, as in Arc. private func menuItems(canCopy: Bool) -> [RowClickCatcher.Item] { + let paneTabID = self.paneTabID + return Self.menuItems( + canCopy: canCopy, showsToolbar: model.showsToolbar, + copy: { [weak actions] in + if let paneTabID { actions?.copyURL(of: paneTabID) } else { actions?.copyURL() } + }, + hide: { [weak actions] in actions?.setToolbarShown(false) }) + } + + /// Copy URL when there's one to copy, and Hide Toolbar only while the + /// preference is on: a split's pane headers show with it off, and hiding + /// them would do nothing. + static func menuItems( + canCopy: Bool, showsToolbar: Bool, copy: @escaping () -> Void, hide: @escaping () -> Void + ) -> [RowClickCatcher.Item] { var items: [RowClickCatcher.Item] = [] if canCopy { - let paneTabID = self.paneTabID - items.append( - .action("Copy URL") { [weak actions] in - if let paneTabID { actions?.copyURL(of: paneTabID) } else { actions?.copyURL() } - }) - items.append(.separator) + items.append(.action("Copy URL", copy)) + } + if showsToolbar { + if !items.isEmpty { items.append(.separator) } + items.append(.action(ToolbarPreference.menuTitle(isOn: true), hide)) } - items.append(.action(ToolbarPreference.menuTitle(isOn: true)) { [weak actions] in actions?.setToolbarShown(false) }) return items } } diff --git a/native/ClairUITests/SplitTests.swift b/native/ClairUITests/SplitTests.swift index b2268d6..1ebbfb2 100644 --- a/native/ClairUITests/SplitTests.swift +++ b/native/ClairUITests/SplitTests.swift @@ -117,6 +117,16 @@ struct SplitLogicTests { if case .submenu = loneItem {} else { Issue.record("Split with Tab isn't a submenu") } } + /// A split's pane headers show with the toolbar off, where Hide Toolbar + /// would do nothing. + @Test(arguments: [true, false]) + func theHeadersMenuOffersHideToolbarOnlyWhileItsOn(showsToolbar: Bool) { + let titles = PageToolbar.menuItems(canCopy: true, showsToolbar: showsToolbar, copy: {}, hide: {}).map(\.title) + #expect(titles == (showsToolbar ? ["Copy URL", nil, "Hide Toolbar"] : ["Copy URL"])) + let blank = PageToolbar.menuItems(canCopy: false, showsToolbar: showsToolbar, copy: {}, hide: {}).map(\.title) + #expect(blank == (showsToolbar ? ["Hide Toolbar"] : [])) + } + @Test func paneHeadersExpandWhileFocusedOrHovered() { let leading = PageHeaderContent.pane(leading: true, toggle: true, expanded: false) #expect(leading.showsSidebarToggle && !leading.showsReload && !leading.showsSplitButton && leading.showsClose) diff --git a/openspec/specs/page-toolbar/spec.md b/openspec/specs/page-toolbar/spec.md index c4571b0..f3f4294 100644 --- a/openspec/specs/page-toolbar/spec.md +++ b/openspec/specs/page-toolbar/spec.md @@ -193,7 +193,7 @@ While the toolbar shows, the strip at the top of the page that moves the window - **THEN** the drag reaches the page and the window stays in place ### Requirement: Turning the toolbar on and off -View SHALL offer "Hide Toolbar", reading "Show Toolbar" while the toolbar is off, with ⇧⌘D, as in Arc. While the toolbar shows, right-clicking it, on its host or a blank area, SHALL open a menu with Copy URL and "Hide Toolbar". While it's off, the sidebar's URL field SHALL have that menu instead, with "Show as Toolbar". The toolbar's buttons SHALL keep their own menus. Each item SHALL change the toolbar preference. +View SHALL offer "Hide Toolbar", reading "Show Toolbar" while the toolbar is off, with ⇧⌘D, as in Arc. While the toolbar shows, right-clicking it, on its host or a blank area, SHALL open a menu with Copy URL and "Hide Toolbar". While it's off, the sidebar's URL field SHALL have that menu instead, with "Show as Toolbar", and a split's pane headers only Copy URL. The toolbar's buttons SHALL keep their own menus. Each item SHALL change the toolbar preference. #### Scenario: Menu bar - **WHEN** the toolbar is shown and the user presses ⇧⌘D @@ -203,6 +203,10 @@ View SHALL offer "Hide Toolbar", reading "Show Toolbar" while the toolbar is off - **WHEN** the toolbar is shown and the user right-clicks its host, or blank space in it - **THEN** the menu offers Copy URL and "Hide Toolbar" +#### Scenario: A pane header with the toolbar off +- **WHEN** the toolbar is off, the window shows a split, and the user right-clicks a pane header's host +- **THEN** the menu offers Copy URL only + #### Scenario: A button's own menu - **WHEN** the toolbar is shown and the user right-clicks its back button - **THEN** the history menu opens, not the toolbar's menu