11import ConversationServiceProvider
22import AppKit
33import SwiftUI
4+ import ComposableArchitecture
45
56public struct ChatTemplateDropdownView : View {
67 @Binding var templates : [ ChatTemplate ]
@@ -10,76 +11,78 @@ public struct ChatTemplateDropdownView: View {
1011 @State private var localMonitor : Any ? = nil
1112
1213 public var body : some View {
13- VStack ( alignment: . leading, spacing: 0 ) {
14- ForEach ( Array ( templates. enumerated ( ) ) , id: \. element. id) { index, template in
15- HStack {
16- Text ( " / " + template. id)
17- . hoverPrimaryForeground ( isHovered: selectedIndex == index)
18- Spacer ( )
19- Text ( template. shortDescription)
20- . hoverSecondaryForeground ( isHovered: selectedIndex == index)
21- }
22- . padding ( . horizontal, 8 )
23- . padding ( . vertical, 6 )
24- . contentShape ( Rectangle ( ) )
25- . onTapGesture {
26- onSelect ( template)
27- }
28- . hoverBackground ( isHovered: selectedIndex == index)
29- . onHover { isHovered in
30- if isHovered {
31- selectedIndex = index
14+ WithPerceptionTracking {
15+ VStack ( alignment: . leading, spacing: 0 ) {
16+ ForEach ( Array ( templates. enumerated ( ) ) , id: \. element. id) { index, template in
17+ HStack {
18+ Text ( " / " + template. id)
19+ . hoverPrimaryForeground ( isHovered: selectedIndex == index)
20+ Spacer ( )
21+ Text ( template. shortDescription)
22+ . hoverSecondaryForeground ( isHovered: selectedIndex == index)
23+ }
24+ . padding ( . horizontal, 8 )
25+ . padding ( . vertical, 6 )
26+ . contentShape ( Rectangle ( ) )
27+ . onTapGesture {
28+ onSelect ( template)
29+ }
30+ . hoverBackground ( isHovered: selectedIndex == index)
31+ . onHover { isHovered in
32+ if isHovered {
33+ selectedIndex = index
34+ }
3235 }
3336 }
3437 }
35- }
36- . background (
37- GeometryReader { geometry in
38- Color . clear
39- . onAppear { frameHeight = geometry. size. height }
40- . onChange ( of: geometry. size. height) { newHeight in
41- frameHeight = newHeight
42- }
38+ . background (
39+ GeometryReader { geometry in
40+ Color . clear
41+ . onAppear { frameHeight = geometry. size. height }
42+ . onChange ( of: geometry. size. height) { newHeight in
43+ frameHeight = newHeight
44+ }
45+ }
46+ )
47+ . background ( . ultraThickMaterial)
48+ . cornerRadius ( 6 )
49+ . shadow ( radius: 2 )
50+ . overlay (
51+ RoundedRectangle ( cornerRadius: 6 )
52+ . stroke ( Color ( nsColor: . separatorColor) , lineWidth: 1 )
53+ )
54+ . frame ( maxWidth: . infinity)
55+ . offset ( y: - 1 * frameHeight)
56+ . onChange ( of: templates) { _ in
57+ selectedIndex = 0
4358 }
44- )
45- . background ( . ultraThickMaterial)
46- . cornerRadius ( 6 )
47- . shadow ( radius: 2 )
48- . overlay (
49- RoundedRectangle ( cornerRadius: 6 )
50- . stroke ( Color ( nsColor: . separatorColor) , lineWidth: 1 )
51- )
52- . frame ( maxWidth: . infinity)
53- . offset ( y: - 1 * frameHeight)
54- . onChange ( of: templates) { _ in
55- selectedIndex = 0
56- }
57- . onAppear {
58- selectedIndex = 0
59- localMonitor = NSEvent . addLocalMonitorForEvents ( matching: . keyDown) { event in
60- switch event. keyCode {
61- case 126 : // Up arrow
62- moveSelection ( up: true )
63- return nil
64- case 125 : // Down arrow
65- moveSelection ( up: false )
66- return nil
67- case 36 : // Return key
68- handleEnter ( )
69- return nil
70- case 48 : // Tab key
71- handleTab ( )
72- return nil // not forwarding the Tab Event which will replace the typed message to "\t"
73- default :
74- break
59+ . onAppear {
60+ selectedIndex = 0
61+ localMonitor = NSEvent . addLocalMonitorForEvents ( matching: . keyDown) { event in
62+ switch event. keyCode {
63+ case 126 : // Up arrow
64+ moveSelection ( up: true )
65+ return nil
66+ case 125 : // Down arrow
67+ moveSelection ( up: false )
68+ return nil
69+ case 36 : // Return key
70+ handleEnter ( )
71+ return nil
72+ case 48 : // Tab key
73+ handleTab ( )
74+ return nil // not forwarding the Tab Event which will replace the typed message to "\t"
75+ default :
76+ break
77+ }
78+ return event
7579 }
76- return event
7780 }
78- }
79- . onDisappear {
80- if let monitor = localMonitor {
81- NSEvent . removeMonitor ( monitor )
82- localMonitor = nil
81+ . onDisappear {
82+ if let monitor = localMonitor {
83+ NSEvent . removeMonitor ( monitor )
84+ localMonitor = nil
85+ }
8386 }
8487 }
8588 }
0 commit comments