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.

Choose a row's arrangement as it is laid out on macOS 27

Țugui Dragoșf484cc1b10dc
diff --git a/Peel/Views/FileSearch/FileSearchList.swift b/Peel/Views/FileSearch/FileSearchList.swift
index 1686d747..6c15b6d2 100644
--- a/Peel/Views/FileSearch/FileSearchList.swift
+++ b/Peel/Views/FileSearch/FileSearchList.swift
@@ -7,7 +7,6 @@ struct FileSearchList: View {
@Environment(ExclusionsStore.self) private var exclusions
@State private var isShowingFilters = false
@State private var isRescanning = false
- @ScaledMetric(relativeTo: .body) private var rowHeight: CGFloat = 48
var body: some View {
@Bindable var search = search
@@ -106,7 +105,6 @@ struct FileSearchList: View {
.accessibilityLabel(Text(Tool.fileSearch.title))
.onKeyPress(.space) { search.toggleChosen() ? .handled : .ignored }
.scrollBarBelowSectionHeaders()
- .startsRows(at: rowHeight)
.scanState(phase, isRescanning: search.isSearching, fadesInResults: false, scan: search.scanRun) {
if search.results == nil {
ContentUnavailableView(
@@ -288,17 +286,3 @@ private struct LeftOutLines: View {
}
}
}
-
-extension View {
- /// Starts a list's rows at `height`. On macOS 27 a list filled all at once from empty, led by a section header,
- /// leaves its rows at the height it starts them at. Building the list again would measure them, but it takes the
- /// focus from the search field above it, so a list that fills as someone types starts them at their own height.
- @ViewBuilder
- fileprivate func startsRows(at height: CGFloat) -> some View {
- if #available(macOS 27, *) {
- environment(\.defaultMinListRowHeight, height)
- } else {
- self
- }
- }
-}
diff --git a/Peel/Views/RemovalRow.swift b/Peel/Views/RemovalRow.swift
index 65c886f8..a29ca267 100644
--- a/Peel/Views/RemovalRow.swift
+++ b/Peel/Views/RemovalRow.swift
@@ -121,45 +121,67 @@ struct RemovalRow: View {
.joined(separator: ", ")
}
+ /// The row's item, with its kind and size beside the path or under it. A list can measure a row before `isCompact`
+ /// is set and not again once it changes, which cuts off the second line, so on macOS 27 the row chooses as it is
+ /// laid out.
@ViewBuilder
private var item: some View {
- if isCompact {
- HStack(alignment: .firstTextBaseline, spacing: 10) {
- iconView
- .frame(width: 20)
- VStack(alignment: .leading, spacing: 2) {
- pathAndBadge
- HStack(spacing: 8) {
- if let kind {
- Text(kind)
- .font(.caption)
- .foregroundStyle(.secondary)
- .lineLimit(1)
- }
- Spacer(minLength: 8)
- sizeText
- .font(.caption)
- .foregroundStyle(.secondary)
- }
- }
+ if #available(macOS 27, *) {
+ ViewThatFits(in: .horizontal) {
+ itemOnOneLine
+ .frame(idealWidth: Self.compactBelow(hasKind: kind != nil) - besideTheItem)
+ itemUnderThePath
}
+ } else if isCompact {
+ itemUnderThePath
} else {
- HStack(alignment: .firstTextBaseline, spacing: 10) {
- iconView
- .frame(width: 20)
+ itemOnOneLine
+ }
+ }
+
+ /// What the row keeps beside its item: the checkbox, the note, and their gaps.
+ private var besideTheItem: CGFloat {
+ 21 + (hasNoteColumn ? Self.controlWidth + 6 : 0)
+ }
+
+ private var itemUnderThePath: some View {
+ HStack(alignment: .firstTextBaseline, spacing: 10) {
+ iconView
+ .frame(width: 20)
+ VStack(alignment: .leading, spacing: 2) {
pathAndBadge
- if let kind {
- Text(kind)
+ HStack(spacing: 8) {
+ if let kind {
+ Text(kind)
+ .font(.caption)
+ .foregroundStyle(.secondary)
+ .lineLimit(1)
+ }
+ Spacer(minLength: 8)
+ sizeText
.font(.caption)
.foregroundStyle(.secondary)
- .lineLimit(1)
- .frame(width: RowColumns.kind, alignment: .leading)
- .help(Text(kind))
}
- sizeText
+ }
+ }
+ }
+
+ private var itemOnOneLine: some View {
+ HStack(alignment: .firstTextBaseline, spacing: 10) {
+ iconView
+ .frame(width: 20)
+ pathAndBadge
+ if let kind {
+ Text(kind)
+ .font(.caption)
.foregroundStyle(.secondary)
- .frame(width: RowColumns.size, alignment: .trailing)
+ .lineLimit(1)
+ .frame(width: RowColumns.kind, alignment: .leading)
+ .help(Text(kind))
}
+ sizeText
+ .foregroundStyle(.secondary)
+ .frame(width: RowColumns.size, alignment: .trailing)
}
}
diff --git a/PeelTests/RemovalRowTests.swift b/PeelTests/RemovalRowTests.swift
new file mode 100644
index 00000000..2783ed97
--- /dev/null
+++ b/PeelTests/RemovalRowTests.swift
@@ -0,0 +1,24 @@
+import AppKit
+@testable import Peel
+import SwiftUI
+import Testing
+
+@MainActor
+struct RemovalRowTests {
+ private final class Rows: RowSelection {
+ var selectedURLs: Set<URL> = []
+ }
+
+ private func height(atWidth width: CGFloat) -> CGFloat {
+ let row = RemovalRow(
+ url: URL(filePath: "/org.example/file.txt"), icon: .symbol("doc"), detail: nil, kind: "Application",
+ size: 1_000, selection: Rows(), isSelected: false
+ )
+ return NSHostingView(rootView: row.frame(width: width)).fittingSize.height
+ }
+
+ @Test func aRowTooNarrowForItsColumnsIsAsTallAsItsSecondLineFromItsFirstLayout() {
+ guard #available(macOS 27, *) else { return }
+ #expect(height(atWidth: 300) > height(atWidth: 900))
+ }
+}