@@ -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+ }
0 commit comments