1+ import Environment
12import SwiftUI
23
34@MainActor
@@ -40,15 +41,8 @@ final class SuggestionPanelViewModel: ObservableObject {
4041
4142 @Published var activeTab : ActiveTab {
4243 didSet {
43- #warning("""
44- TODO: There should be a better way for that
45- Currently, we have to make the app an accessory so that we can type things in the chat mode.
46- But in other modes, we want to keep it prohibited so the helper app won't take over the focus.
47- """ )
48- if case .chat = activeTab {
49- NSApp.setActivationPolicy(.accessory)
50- } else {
51- NSApp.setActivationPolicy(.prohibited)
44+ if activeTab != oldValue {
45+ onActiveTabChanged ? ( activeTab)
5246 }
5347 }
5448 }
@@ -61,6 +55,7 @@ final class SuggestionPanelViewModel: ObservableObject {
6155 var onRejectButtonTapped : ( ( ) -> Void ) ?
6256 var onPreviousButtonTapped : ( ( ) -> Void ) ?
6357 var onNextButtonTapped : ( ( ) -> Void ) ?
58+ var onActiveTabChanged : ( ( ActiveTab ) -> Void ) ?
6459
6560 public init (
6661 content: Content ? = nil ,
@@ -71,7 +66,8 @@ final class SuggestionPanelViewModel: ObservableObject {
7166 onAcceptButtonTapped: ( ( ) -> Void ) ? = nil ,
7267 onRejectButtonTapped: ( ( ) -> Void ) ? = nil ,
7368 onPreviousButtonTapped: ( ( ) -> Void ) ? = nil ,
74- onNextButtonTapped: (() -> Void)? = nil
69+ onNextButtonTapped: ( ( ) -> Void ) ? = nil ,
70+ onActiveTabChanged: ( ( ActiveTab ) -> Void ) ? = nil
7571 ) {
7672 self . content = content
7773 self . chat = chat
@@ -82,6 +78,7 @@ final class SuggestionPanelViewModel: ObservableObject {
8278 self . onRejectButtonTapped = onRejectButtonTapped
8379 self . onPreviousButtonTapped = onPreviousButtonTapped
8480 self . onNextButtonTapped = onNextButtonTapped
81+ self . onActiveTabChanged = onActiveTabChanged
8582 }
8683
8784 func adjustActiveTabAndShowHideIfNeeded( tab: ActiveTab ) {
@@ -90,11 +87,13 @@ final class SuggestionPanelViewModel: ObservableObject {
9087 if content != nil {
9188 activeTab = . suggestion
9289 isPanelDisplayed = true
90+ return
9391 }
9492 case . chat:
9593 if chat != nil {
9694 activeTab = . chat
9795 isPanelDisplayed = true
96+ return
9897 }
9998 }
10099
@@ -158,6 +157,7 @@ struct SuggestionPanelView: View {
158157 Color . userChatContentBackground,
159158 in: RoundedRectangle ( cornerRadius: 8 , style: . continuous)
160159 )
160+ . fixedSize ( horizontal: false , vertical: true )
161161 } )
162162 . buttonStyle ( . plain)
163163 . xcodeStyleFrame ( )
@@ -187,6 +187,7 @@ struct SuggestionPanelView: View {
187187 Color . userChatContentBackground,
188188 in: RoundedRectangle ( cornerRadius: 8 , style: . continuous)
189189 )
190+ . fixedSize ( horizontal: false , vertical: true )
190191 } )
191192 . buttonStyle ( . plain)
192193 . xcodeStyleFrame ( )
@@ -211,6 +212,9 @@ struct SuggestionPanelView: View {
211212 . animation ( . easeInOut( duration: 0.2 ) , value: viewModel. chat)
212213 . animation ( . easeInOut( duration: 0.2 ) , value: viewModel. activeTab)
213214 . animation ( . easeInOut( duration: 0.2 ) , value: viewModel. isPanelDisplayed)
215+ . shadow ( color: . black. opacity ( 0.1 ) , radius: 2 )
216+ . padding ( 2 )
217+ . frame ( maxWidth: Style . panelWidth, maxHeight: Style . panelHeight)
214218 }
215219}
216220
@@ -221,7 +225,7 @@ struct CommandButtonStyle: ButtonStyle {
221225 configuration. label
222226 . padding ( . vertical, 4 )
223227 . padding ( . horizontal, 8 )
224- .foregroundColor(.white)
228+ . foregroundColor ( . white)
225229 . background (
226230 RoundedRectangle ( cornerRadius: 4 , style: . continuous)
227231 . fill ( color. opacity ( configuration. isPressed ? 0.8 : 1 ) )
0 commit comments