@@ -9,18 +9,31 @@ final class SuggestionPanelViewModel: ObservableObject {
99 @Published var suggestionCount : Int
1010 @Published var currentSuggestionIndex : Int
1111
12+ var onAcceptButtonTapped : ( ( ) -> Void ) ?
13+ var onRejectButtonTapped : ( ( ) -> Void ) ?
14+ var onPreviousButtonTapped : ( ( ) -> Void ) ?
15+ var onNextButtonTapped : ( ( ) -> Void ) ?
16+
1217 public init (
1318 startLineIndex: Int = 0 ,
1419 suggestion: [ String ] = [ ] ,
1520 isPanelDisplayed: Bool = false ,
1621 suggestionCount: Int = 0 ,
17- currentSuggestionIndex: Int = 0
22+ currentSuggestionIndex: Int = 0 ,
23+ onAcceptButtonTapped: ( ( ) -> Void ) ? = nil ,
24+ onRejectButtonTapped: ( ( ) -> Void ) ? = nil ,
25+ onPreviousButtonTapped: ( ( ) -> Void ) ? = nil ,
26+ onNextButtonTapped: ( ( ) -> Void ) ? = nil
1827 ) {
1928 self . startLineIndex = startLineIndex
2029 self . suggestion = suggestion
2130 self . isPanelDisplayed = isPanelDisplayed
2231 self . suggestionCount = suggestionCount
2332 self . currentSuggestionIndex = currentSuggestionIndex
33+ self . onAcceptButtonTapped = onAcceptButtonTapped
34+ self . onRejectButtonTapped = onRejectButtonTapped
35+ self . onPreviousButtonTapped = onPreviousButtonTapped
36+ self . onNextButtonTapped = onNextButtonTapped
2437 }
2538}
2639
@@ -107,35 +120,47 @@ struct CodeBlock: View {
107120 } ) )
108121 }
109122}
110-
123+
111124struct ToolBar : View {
112125 @ObservedObject var viewModel : SuggestionPanelViewModel
113126
114127 var body : some View {
115128 HStack {
116129 Button ( action: {
117130 Task {
131+ if let block = viewModel. onPreviousButtonTapped {
132+ block ( )
133+ return
134+ }
118135 try await Environment . triggerAction ( " Previous Suggestion " )
119136 }
120137 } ) {
121138 Image ( systemName: " chevron.left " )
122139 } . buttonStyle ( . plain)
123-
140+
124141 Text ( " \( viewModel. currentSuggestionIndex + 1 ) / \( viewModel. suggestionCount) " )
125142 . monospacedDigit ( )
126-
143+
127144 Button ( action: {
128145 Task {
146+ if let block = viewModel. onNextButtonTapped {
147+ block ( )
148+ return
149+ }
129150 try await Environment . triggerAction ( " Next Suggestion " )
130151 }
131152 } ) {
132- Image ( systemName: " chevron.right " )
153+ Image ( systemName: " chevron.right " )
133154 } . buttonStyle ( . plain)
134155
135156 Spacer ( )
136157
137158 Button ( action: {
138159 Task {
160+ if let block = viewModel. onRejectButtonTapped {
161+ block ( )
162+ return
163+ }
139164 try await Environment . triggerAction ( " Reject Suggestion " )
140165 }
141166 } ) {
@@ -144,6 +169,10 @@ struct ToolBar: View {
144169
145170 Button ( action: {
146171 Task {
172+ if let block = viewModel. onAcceptButtonTapped {
173+ block ( )
174+ return
175+ }
147176 try await Environment . triggerAction ( " Accept Suggestion " )
148177 }
149178 } ) {
0 commit comments