Skip to content

Commit edf4e56

Browse files
Xander-AJclaude
authored andcommitted
The Downloads card stands by the button at the column's foot, not at its top (#1364, #1350)
Both copies of the doors heard the list being asked for and the hidden one up in the lights' row won; FetchDoor now floats the card only from the copy that is drawn. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e0c9c95 commit edf4e56

4 files changed

Lines changed: 97 additions & 7 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ in [ROADMAP.md](ROADMAP.md).
1515

1616
- Closing a window while another stays open stops that window’s background checks for tabs to put to sleep. `swift test --filter KeepAwakeTests`. Thanks [@shawn-t516](https://github.com/shawn-t516) ([#1356](https://github.com/driceroland/Search/pull/1356))
1717
- A draft typed into an embedded form keeps its tab awake, including a form hosted by another site. Clearing it lets the tab sleep again. `swift test --filter PageDraftTests`. Thanks [@shawn-t516](https://github.com/shawn-t516) ([#1357](https://github.com/driceroland/Search/pull/1357))
18+
- The Downloads card stands by the button you clicked when Settings › Appearance › Tabs › Buttons at the top is on and the column is too narrow for them there: it hung from the top of the column instead of beside the downloads button at its foot. `swift test --filter DownloadsAnchorTests`. Thanks [@Xander-AJ](https://github.com/Xander-AJ) ([#1364](https://github.com/driceroland/Search/pull/1364), [#1350](https://github.com/driceroland/Search/issues/1350))
1819

1920
### Held back
2021

‎Sources/Search/Fetching.swift‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,11 @@ struct FetchDoor: View {
662662
/// Which side of it the floating card stands on: under it in the row,
663663
/// beside it at the column's foot.
664664
let arrowEdge: Edge
665+
/// Whether this is the copy the person can see. With the doors up or at
666+
/// the foot, the column draws both rows and hides the one not in use, and
667+
/// both copies hear the list being asked for: the hidden one standing the
668+
/// card beside a button nobody sees put it at the column's top (#1350).
669+
let live: Bool
665670

666671
@State private var hovering = false
667672
/// Its view, for the card to stand beside. Held, not drawn from.
@@ -671,11 +676,12 @@ struct FetchDoor: View {
671676
weak var view: NSView?
672677
}
673678

674-
init(browser: Browser, fetches: Fetches, arrowEdge: Edge = .bottom) {
679+
init(browser: Browser, fetches: Fetches, arrowEdge: Edge = .bottom, live: Bool = true) {
675680
self.browser = browser
676681
self.fetches = fetches
677682
self.prefs = browser.prefs
678683
self.arrowEdge = arrowEdge
684+
self.live = live
679685
}
680686

681687
/// Whether it is in the row, for those that make room for it. Its list
@@ -687,7 +693,7 @@ struct FetchDoor: View {
687693

688694
private func float(_ on: Bool) {
689695
guard on else { return DownloadsFloat.hide(for: browser, animated: true) }
690-
guard let view = spot.view, view.window != nil else { return }
696+
guard live, let view = spot.view, view.window != nil else { return }
691697
DownloadsFloat.show(browser, from: view, edge: arrowEdge)
692698
}
693699

@@ -746,6 +752,8 @@ struct FetchDoor: View {
746752
.help("Downloads (⇧⌘J)")
747753
.background(ButtonSpot { spot.view = $0; if browser.downloadsHanging { float(true) } })
748754
.onChange(of: browser.downloadsHanging) { _, on in float(on) }
755+
// The doors moving while the list hangs: it follows them.
756+
.onChange(of: live) { _, _ in float(browser.downloadsHanging) }
749757
.onDisappear { DownloadsFloat.hide(for: browser) }
750758
.transition(.scale(scale: 0.6).combined(with: .opacity))
751759
.animation(Motion.quick, value: fetches.done)

‎Sources/Search/Side.swift‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ struct SideBar: View {
213213
// moved, they were laid out again at every frame of it.
214214
.overlay(alignment: .trailing) {
215215
if prefs.doorsUp {
216-
SideFoot(browser: browser, prefs: prefs, fetches: browser.fetches, up: true, width: upRoom)
216+
SideFoot(browser: browser, prefs: prefs, fetches: browser.fetches, up: true, live: doorsTop, width: upRoom)
217217
.fixedSize()
218218
.opacity(doorsTop ? 1 : 0)
219219
.animation(doorsTop ? SideBar.doorsIn : SideBar.doorsOut, value: doorsTop)
@@ -1578,7 +1578,7 @@ struct SideBar: View {
15781578

15791579
/// One small door at the bottom: the settings.
15801580
private var foot: some View {
1581-
SideFoot(browser: browser, prefs: prefs, fetches: browser.fetches, vertical: icons, width: width)
1581+
SideFoot(browser: browser, prefs: prefs, fetches: browser.fetches, vertical: icons, live: doorsFoot, width: width)
15821582
}
15831583

15841584
}
@@ -1598,6 +1598,9 @@ private struct SideFoot: View {
15981598
/// Up in the lights' row, right of back, forward and reload, laid out
15991599
/// to its far end: `width` is then what that row has left.
16001600
var up = false
1601+
/// Whether this row is the one drawn; the other is kept, hidden, and must
1602+
/// not take the downloads list's card for itself (see FetchDoor.live).
1603+
var live = true
16011604
/// The column's width, as it is drawn; up, the room right of the helm.
16021605
let width: CGFloat
16031606

@@ -1606,7 +1609,7 @@ private struct SideFoot: View {
16061609
VStack(spacing: 2) {
16071610
// An agent connected in this window: a click on it is Stop.
16081611
AgentStatus(browser: browser, style: .icon)
1609-
FetchDoor(browser: browser, fetches: fetches, arrowEdge: prefs.sidePosition == .right ? .leading : .trailing)
1612+
FetchDoor(browser: browser, fetches: fetches, arrowEdge: prefs.sidePosition == .right ? .leading : .trailing, live: live)
16101613
ExtensionSlot(browser: browser, edge: prefs.sidePosition == .right ? .leading : .trailing, room: 0)
16111614
BookmarkDoor(browser: browser, arrowEdge: prefs.sidePosition == .right ? .leading : .trailing)
16121615
SpaceButtons(browser: browser, vertical: true)
@@ -1623,7 +1626,7 @@ private struct SideFoot: View {
16231626
HStack(spacing: 2) {
16241627
if Profiles.shared.several { ProfileBadge(browser: browser) }
16251628
if prefs.usesSpaces && !prefs.showsSpaceButtons { SpaceDot(browser: browser, names: false) }
1626-
FetchDoor(browser: browser, fetches: fetches, arrowEdge: .bottom)
1629+
FetchDoor(browser: browser, fetches: fetches, arrowEdge: .bottom, live: live)
16271630
BookmarkDoor(browser: browser, arrowEdge: .bottom)
16281631
SpaceButtons(browser: browser)
16291632
ExtensionSlot(browser: browser, edge: .bottom, room: room)
@@ -1636,7 +1639,7 @@ private struct SideFoot: View {
16361639
BookmarkDoor(browser: browser, arrowEdge: prefs.sidePosition == .right ? .leading : .trailing)
16371640
SpaceButtons(browser: browser)
16381641
// Only while a download is running, and a moment after.
1639-
FetchDoor(browser: browser, fetches: fetches, arrowEdge: prefs.sidePosition == .right ? .leading : .trailing)
1642+
FetchDoor(browser: browser, fetches: fetches, arrowEdge: prefs.sidePosition == .right ? .leading : .trailing, live: live)
16401643
// With a button per space the row is centred under the
16411644
// column: at one side, a row of spaces read as a toolbar
16421645
// that had slid off. Otherwise at the side, as it always was.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import AppKit
2+
import SwiftUI
3+
import XCTest
4+
@testable import Search
5+
6+
/// The downloads card stands by the button that can be seen. With Settings ›
7+
/// Buttons at the top on, the column draws the doors at its foot as well as
8+
/// up in the lights' row and hides whichever it isn't using; both buttons
9+
/// heard the list being asked for, and the hidden one at the top won, so the
10+
/// card hung from the column's top instead of its foot (#1350).
11+
@MainActor
12+
final class DownloadsAnchorTests: XCTestCase {
13+
private var window: NSWindow?
14+
private var browser: Browser?
15+
private var restore: (() -> Void)?
16+
17+
override class func setUp() {
18+
TestWorld.enter()
19+
super.setUp()
20+
}
21+
22+
override func tearDown() async throws {
23+
browser?.downloadsHanging = false
24+
window?.contentView = nil
25+
window?.close()
26+
browser?.closeAll()
27+
restore?()
28+
window = nil
29+
browser = nil
30+
try await settle()
31+
try await super.tearDown()
32+
}
33+
34+
func testCardStandsByTheFootWhenTheDoorsHaveNoRoomUp() async throws {
35+
let panel = try await hang(columnWidth: 250)
36+
let column = try XCTUnwrap(window)
37+
XCTAssertLessThan(panel.frame.midY, column.frame.midY,
38+
"the doors are at the foot: the card hangs beside them, not from the top")
39+
}
40+
41+
func testCardHangsFromTheDoorsUpWhenTheyFit() async throws {
42+
let panel = try await hang(columnWidth: 420)
43+
let column = try XCTUnwrap(window)
44+
XCTAssertGreaterThan(panel.frame.midY, column.frame.midY,
45+
"the doors are up in the lights' row: the card hangs from them")
46+
}
47+
48+
private func hang(columnWidth: CGFloat) async throws -> NSWindow {
49+
_ = NSApplication.shared
50+
NSApp.setActivationPolicy(.prohibited)
51+
let prefs = Shared.prefs
52+
let before = (prefs.sidebar, prefs.doorsUp, prefs.alwaysShowsDownloads, prefs.downloadsOpening, prefs.sideWidth)
53+
restore = {
54+
(prefs.sidebar, prefs.doorsUp, prefs.alwaysShowsDownloads, prefs.downloadsOpening, prefs.sideWidth) = before
55+
}
56+
let browser = Browser(record: WindowRecord())
57+
self.browser = browser
58+
browser.prefs.sidebar = true
59+
browser.prefs.doorsUp = true
60+
browser.prefs.alwaysShowsDownloads = true
61+
browser.prefs.downloadsOpening = .popover
62+
browser.prefs.sideWidth = columnWidth
63+
let window = NSWindow(contentRect: NSRect(x: -20_000, y: -20_000, width: columnWidth, height: 500),
64+
styleMask: .borderless, backing: .buffered, defer: false)
65+
window.isReleasedWhenClosed = false
66+
window.contentView = NSHostingView(rootView: SideBar(browser: browser, prefs: browser.prefs))
67+
window.orderFrontRegardless()
68+
self.window = window
69+
try await settle()
70+
browser.showDownloads()
71+
try await settle()
72+
return try XCTUnwrap(window.childWindows?.first, "the card must be showing")
73+
}
74+
75+
private func settle() async throws {
76+
try await Task.sleep(for: .milliseconds(400))
77+
}
78+
}

0 commit comments

Comments
 (0)