Skip to content

Commit a655b29

Browse files
committed
feat: merge consecutive selection highlights
1 parent db37e14 commit a655b29

3 files changed

Lines changed: 69 additions & 15 deletions

File tree

‎EdgeMark/UI/Components/PanelRowBackground.swift‎

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,86 @@
11
import SwiftUI
22

3+
/// Describes a selected row's place within a consecutive selection run.
4+
enum RowSelectionPosition {
5+
case none
6+
case single
7+
case first
8+
case middle
9+
case last
10+
11+
static func resolve(
12+
_ id: NoteStore.SelectableID,
13+
in visibleOrder: [NoteStore.SelectableID],
14+
selection: Set<NoteStore.SelectableID>,
15+
) -> Self {
16+
guard selection.contains(id), let index = visibleOrder.firstIndex(of: id) else {
17+
return .none
18+
}
19+
20+
let joinsPrevious = index > visibleOrder.startIndex
21+
&& selection.contains(visibleOrder[index - 1])
22+
let joinsNext = index < visibleOrder.index(before: visibleOrder.endIndex)
23+
&& selection.contains(visibleOrder[index + 1])
24+
25+
switch (joinsPrevious, joinsNext) {
26+
case (false, false): return .single
27+
case (false, true): return .first
28+
case (true, true): return .middle
29+
case (true, false): return .last
30+
}
31+
}
32+
33+
var isSelected: Bool {
34+
self != .none
35+
}
36+
37+
fileprivate var cornerRadii: RectangleCornerRadii {
38+
let radius = SurfaceMetrics.panelCornerRadius
39+
switch self {
40+
case .none, .single:
41+
return RectangleCornerRadii(
42+
topLeading: radius,
43+
bottomLeading: radius,
44+
bottomTrailing: radius,
45+
topTrailing: radius,
46+
)
47+
case .first:
48+
return RectangleCornerRadii(topLeading: radius, topTrailing: radius)
49+
case .middle:
50+
return RectangleCornerRadii()
51+
case .last:
52+
return RectangleCornerRadii(bottomLeading: radius, bottomTrailing: radius)
53+
}
54+
}
55+
}
56+
357
/// Shared selection and hover surface for note and folder rows.
458
/// Active row states adopt Liquid Glass when enabled; classic mode keeps the established fills.
559
struct PanelRowBackground: View {
660
@Environment(AppSettings.self) private var appSettings
761

862
let isHovered: Bool
9-
var isSelected = false
63+
var selectionPosition: RowSelectionPosition = .none
1064

11-
private var shape: RoundedRectangle {
12-
RoundedRectangle(
13-
cornerRadius: SurfaceMetrics.panelCornerRadius,
65+
private var shape: UnevenRoundedRectangle {
66+
UnevenRoundedRectangle(
67+
cornerRadii: selectionPosition.cornerRadii,
1468
style: .continuous,
1569
)
1670
}
1771

1872
var body: some View {
19-
if #available(macOS 26.0, *), appSettings.usesLiquidGlass, isHovered || isSelected {
73+
if #available(macOS 26.0, *), appSettings.usesLiquidGlass, isHovered || selectionPosition.isSelected {
2074
shape
21-
.fill(isSelected ? Color.accentColor.opacity(0.14) : .clear)
75+
.fill(selectionPosition.isSelected ? Color.accentColor.opacity(0.14) : .clear)
2276
.glassEffect(.regular.interactive(), in: shape)
2377
} else {
2478
shape.fill(classicFill)
2579
}
2680
}
2781

2882
private var classicFill: Color {
29-
if isSelected {
83+
if selectionPosition.isSelected {
3084
return Color.accentColor.opacity(isHovered ? 0.28 : 0.20)
3185
}
3286
return Color.primary.opacity(isHovered ? 0.06 : 0)

‎EdgeMark/UI/Navigation/HomeFolderView.swift‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ struct HomeFolderView: View {
465465
date: appSettings.folderDate(for: folder),
466466
iconWidth: iconWidth,
467467
color: folder.color,
468-
isSelected: noteStore.isSelected(id),
468+
selectionPosition: .resolve(id, in: visibleOrder, selection: noteStore.selection),
469469
)
470470
.rowClick(
471471
onSingle: { mods in
@@ -516,7 +516,7 @@ struct HomeFolderView: View {
516516
NoteRowView(
517517
note: note,
518518
iconWidth: iconWidth,
519-
isSelected: noteStore.isSelected(id),
519+
selectionPosition: .resolve(id, in: visibleOrder, selection: noteStore.selection),
520520
)
521521
.rowClick(
522522
onSingle: { mods in
@@ -865,7 +865,7 @@ struct FolderRowView: View {
865865
var date: Date?
866866
let iconWidth: CGFloat
867867
var color: TagColor?
868-
var isSelected: Bool = false
868+
var selectionPosition: RowSelectionPosition = .none
869869

870870
@State private var isHovered = false
871871

@@ -900,7 +900,7 @@ struct FolderRowView: View {
900900
.padding(.horizontal, 8)
901901
.padding(.vertical, 10)
902902
.background {
903-
PanelRowBackground(isHovered: isHovered, isSelected: isSelected)
903+
PanelRowBackground(isHovered: isHovered, selectionPosition: selectionPosition)
904904
}
905905
.padding(.horizontal, 8)
906906
.contentShape(Rectangle())
@@ -945,7 +945,7 @@ private struct FolderCountBadge: View {
945945
struct NoteRowView: View {
946946
let note: Note
947947
let iconWidth: CGFloat
948-
var isSelected: Bool = false
948+
var selectionPosition: RowSelectionPosition = .none
949949

950950
@State private var isHovered = false
951951

@@ -983,7 +983,7 @@ struct NoteRowView: View {
983983
.padding(.horizontal, 8)
984984
.padding(.vertical, 10)
985985
.background {
986-
PanelRowBackground(isHovered: isHovered, isSelected: isSelected)
986+
PanelRowBackground(isHovered: isHovered, selectionPosition: selectionPosition)
987987
}
988988
.padding(.horizontal, 8)
989989
.contentShape(Rectangle())

‎EdgeMark/UI/Navigation/NoteListView.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ struct NoteListView: View {
216216
date: appSettings.folderDate(for: folder),
217217
iconWidth: iconWidth,
218218
color: folder.color,
219-
isSelected: noteStore.isSelected(id),
219+
selectionPosition: .resolve(id, in: visibleOrder, selection: noteStore.selection),
220220
)
221221
.rowClick(
222222
onSingle: { mods in
@@ -266,7 +266,7 @@ struct NoteListView: View {
266266
NoteRowView(
267267
note: note,
268268
iconWidth: iconWidth,
269-
isSelected: noteStore.isSelected(id),
269+
selectionPosition: .resolve(id, in: visibleOrder, selection: noteStore.selection),
270270
)
271271
.rowClick(
272272
onSingle: { mods in

0 commit comments

Comments
 (0)