Skip to content

Commit f11ce8c

Browse files
committed
feat: add quick path details on title hover
1 parent dfa99a5 commit f11ce8c

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

‎EdgeMark/UI/Components/NoteHeaderTitle.swift‎

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct NoteHeaderTitle: View {
4848
.frame(maxWidth: .infinity, alignment: .leading)
4949
.layoutPriority(1)
5050
.contentShape(Rectangle())
51-
.help(hoverDetails)
51+
.quickHoverHelp(hoverDetails)
5252
.accessibilityAddTraits(.isHeader)
5353
}
5454

@@ -61,3 +61,56 @@ struct NoteHeaderTitle: View {
6161
].joined(separator: "\n")
6262
}
6363
}
64+
65+
/// Path details that appear faster than the system `.help` delay.
66+
private struct QuickHoverHelpModifier: ViewModifier {
67+
let text: String
68+
69+
@State private var isPresented = false
70+
@State private var revealTask: Task<Void, Never>?
71+
72+
func body(content: Content) -> some View {
73+
content
74+
.onHover(perform: updateHover)
75+
.popover(
76+
isPresented: $isPresented,
77+
attachmentAnchor: .rect(.bounds),
78+
arrowEdge: .top,
79+
) {
80+
Text(text)
81+
.font(.caption)
82+
.multilineTextAlignment(.leading)
83+
.fixedSize(horizontal: true, vertical: true)
84+
.padding(.horizontal, 8)
85+
.padding(.vertical, 6)
86+
.allowsHitTesting(false)
87+
}
88+
.onDisappear(perform: cancelReveal)
89+
}
90+
91+
private func updateHover(_ hovering: Bool) {
92+
revealTask?.cancel()
93+
94+
guard hovering else {
95+
isPresented = false
96+
return
97+
}
98+
99+
revealTask = Task { @MainActor in
100+
try? await Task.sleep(nanoseconds: 200_000_000)
101+
guard !Task.isCancelled else { return }
102+
isPresented = true
103+
}
104+
}
105+
106+
private func cancelReveal() {
107+
revealTask?.cancel()
108+
isPresented = false
109+
}
110+
}
111+
112+
extension View {
113+
func quickHoverHelp(_ text: String) -> some View {
114+
modifier(QuickHoverHelpModifier(text: text))
115+
}
116+
}

‎EdgeMark/UI/Navigation/NoteListView.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct NoteListView: View {
7878
.lineLimit(1)
7979
.truncationMode(.tail)
8080
.layoutPriority(1)
81-
.help(folderPath)
81+
.quickHoverHelp(folderPath)
8282
.frame(maxWidth: .infinity, alignment: .leading)
8383

8484
HStack(spacing: SurfaceMetrics.controlGroupSpacing) {

0 commit comments

Comments
 (0)