Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Keep the list's divider in place when the sidebar is dragged closed on macOS 27

Țugui Dragoș7dc1f7254054
diff --git a/Peel/Navigation/ListColumn.swift b/Peel/Navigation/ListColumn.swift
index 1942fda9..a79b55a4 100644
--- a/Peel/Navigation/ListColumn.swift
+++ b/Peel/Navigation/ListColumn.swift
@@ -25,6 +25,8 @@ final class ListColumn {
@ObservationIgnored private var covered: CGFloat = 0
@ObservationIgnored private weak var columns: NSSplitViewController?
@ObservationIgnored private var pin: NSLayoutConstraint?
+ @ObservationIgnored private weak var watchedSidebar: NSSplitViewItem?
+ @ObservationIgnored private var sidebarWatch: NSKeyValueObservation?
/// The list's width without the sidebar: also the part the sidebar covered, so the divider stays, as far as the
/// page's 480 points allow.
@@ -38,11 +40,29 @@ final class ListColumn {
guard let columns = shownColumns, place(of: 0, in: columns) != nil, place(of: 2, in: columns) != nil else {
return false
}
+ if #available(macOS 27, *) { watch(columns.splitViewItems[0]) }
measure(columns)
fit()
return true
}
+ /// A drag on the sidebar's edge, or a double click on it, collapses the sidebar through AppKit, while SwiftUI's
+ /// `columns` follows only once the columns are laid out. On macOS 27 the page took the sidebar's room meanwhile, so
+ /// the slide starts here, before the change. A change SwiftUI asked for has already set `aside`.
+ private func watch(_ sidebar: NSSplitViewItem) {
+ guard watchedSidebar !== sidebar else { return }
+ watchedSidebar = sidebar
+ // `collapsed` is KVO compliant and follows user interaction (`NSSplitViewItem.h`).
+ sidebarWatch = sidebar.observe(\.isCollapsed, options: [.prior]) { [weak self] item, change in
+ guard change.isPrior else { return }
+ let collapsing = !item.isCollapsed
+ MainActor.assumeIsolated {
+ guard let self, collapsing != self.aside else { return }
+ self.sidebarSlides(aside: collapsing, windowWidth: self.windowWidth)
+ }
+ }
+ }
+
/// Called as the sidebar starts to hide or return.
func sidebarSlides(aside: Bool, windowWidth: CGFloat) {
self.aside = aside
diff --git a/PeelTests/ListColumnTests.swift b/PeelTests/ListColumnTests.swift
index 67695a51..a9e0ee16 100644
--- a/PeelTests/ListColumnTests.swift
+++ b/PeelTests/ListColumnTests.swift
@@ -71,6 +71,24 @@ struct ListColumnTests {
#expect(column.widths == ListColumn.width...ListColumn.width)
}
+ @Test func theDividerStaysWhereItIsWhenAppKitCollapsesTheSidebarItself() throws {
+ let (window, controller) = columns()
+ let column = ListColumn()
+ #expect(column.found(controller))
+ column.rest(aside: false, windowWidth: 1307)
+ apply(column, to: controller, in: window)
+ let start = try #require(pageStart(of: controller))
+
+ // What a drag on the sidebar's edge does: AppKit collapses the item, and SwiftUI's columns follow later.
+ controller.splitViewItems[0].isCollapsed = true
+ apply(column, to: controller, in: window)
+ if #available(macOS 27, *) {
+ #expect(pageStart(of: controller) == start)
+ } else {
+ #expect(column.widths == ListColumn.width...ListColumn.width)
+ }
+ }
+
@Test func aHiddenSidebarLeavesThePageItsWidthInANarrowWindow() {
let (window, controller) = columns()
let column = ListColumn()