|
1 | 1 | import ActiveApplicationMonitor |
2 | 2 | import AppKit |
| 3 | +import Dependencies |
3 | 4 | import Preferences |
4 | 5 | import SuggestionInjector |
5 | 6 | import SuggestionModel |
@@ -210,7 +211,13 @@ struct PseudoCommandHandler { |
210 | 211 | guard let focusElement = application.focusedElement, |
211 | 212 | focusElement.description == "Source Editor" |
212 | 213 | else { return } |
213 | | - guard let (content, lines, _, cursorPosition, cursorOffset) = await getFileContent(sourceEditor: nil) |
| 214 | + guard let ( |
| 215 | + content, |
| 216 | + lines, |
| 217 | + _, |
| 218 | + cursorPosition, |
| 219 | + cursorOffset |
| 220 | + ) = await getFileContent(sourceEditor: nil) |
214 | 221 | else { |
215 | 222 | PresentInWindowSuggestionPresenter() |
216 | 223 | .presentErrorMessage("Unable to get file content.") |
@@ -266,7 +273,13 @@ struct PseudoCommandHandler { |
266 | 273 | guard let focusElement = application.focusedElement, |
267 | 274 | focusElement.description == "Source Editor" |
268 | 275 | else { return } |
269 | | - guard let (content, lines, _, cursorPosition, cursorOffset) = await getFileContent(sourceEditor: nil) |
| 276 | + guard let ( |
| 277 | + content, |
| 278 | + lines, |
| 279 | + _, |
| 280 | + cursorPosition, |
| 281 | + cursorOffset |
| 282 | + ) = await getFileContent(sourceEditor: nil) |
270 | 283 | else { |
271 | 284 | PresentInWindowSuggestionPresenter() |
272 | 285 | .presentErrorMessage("Unable to get file content.") |
@@ -301,12 +314,35 @@ struct PseudoCommandHandler { |
301 | 314 | await filespace.reset() |
302 | 315 | PresentInWindowSuggestionPresenter().discardSuggestion(fileURL: documentURL) |
303 | 316 | } |
304 | | - |
305 | | - func openChat() { |
306 | | - Task { @MainActor in |
307 | | - let store = Service.shared.guiController.store |
308 | | - await store.send(.createChatGPTChatTabIfNeeded) |
309 | | - await store.send(.openChatPanel(forceDetach: false)) |
| 317 | + |
| 318 | + func openChat(forceDetach: Bool) { |
| 319 | + switch UserDefaults.shared.value(for: \.openChatMode) { |
| 320 | + case .chatPanel: |
| 321 | + Task { @MainActor in |
| 322 | + let store = Service.shared.guiController.store |
| 323 | + await store.send(.createChatGPTChatTabIfNeeded).finish() |
| 324 | + store.send(.openChatPanel(forceDetach: false)) |
| 325 | + } |
| 326 | + case .browser: |
| 327 | + let urlString = UserDefaults.shared.value(for: \.openChatInBrowserURL) |
| 328 | + let openInApp = UserDefaults.shared.value(for: \.openChatInBrowserInInAppBrowser) |
| 329 | + guard let url = URL(string: urlString) else { |
| 330 | + let alert = NSAlert() |
| 331 | + alert.messageText = "Invalid URL" |
| 332 | + alert.informativeText = "The URL provided is not valid." |
| 333 | + alert.alertStyle = .warning |
| 334 | + alert.runModal() |
| 335 | + return |
| 336 | + } |
| 337 | + |
| 338 | + if openInApp { |
| 339 | + return |
| 340 | + } else { |
| 341 | + Task { |
| 342 | + @Dependency(\.openURL) var openURL |
| 343 | + await openURL(url) |
| 344 | + } |
| 345 | + } |
310 | 346 | } |
311 | 347 | } |
312 | 348 | } |
|
0 commit comments