mac: focus the message box after adding a file (drag-drop or picker) (#80)
Extract focusComposer() (used on app re-focus) and call it after a Finder file-drop and after the "+" open-panel completes, so the caret lands in #text and you can type a caption immediately.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 file changed,
+12
−2
ios/LChatMac/ChatFeedWebView.swift+12 −2
diff --git a/ios/LChatMac/ChatFeedWebView.swift b/ios/LChatMac/ChatFeedWebView.swift| index cb4c6fd..8db1110 100644 |
| --- a/ios/LChatMac/ChatFeedWebView.swift |
| +++ b/ios/LChatMac/ChatFeedWebView.swift |
| @@ -163,7 +163,15 @@ struct ChatFeedWebView: NSViewRepresentable { |
| // message box (chat.js's #text) so you can start typing immediately. Only the |
| // active instance reacts, and only when a composer is present. |
| @objc private func appDidBecomeActive() { |
| - guard app.selection == chat.id, let web = webView else { return } |
| + guard app.selection == chat.id else { return } |
| + focusComposer() |
| + } |
| + |
| + // Put the caret in this instance's message box (chat.js's #text) so you can |
| + // type right away — used on app re-focus and after adding a file. No-op when |
| + // no composer is present. |
| + func focusComposer() { |
| + guard let web = webView else { return } |
| DispatchQueue.main.async { |
| web.window?.makeFirstResponder(web) |
| web.evaluateJavaScript( |
| @@ -186,6 +194,7 @@ struct ChatFeedWebView: NSViewRepresentable { |
| let json = try? JSONSerialization.data(withJSONObject: items), |
| let arg = String(data: json, encoding: .utf8) else { return } |
| web.evaluateJavaScript("window.__lchatAddFiles && window.__lchatAddFiles(\(arg))", completionHandler: nil) |
| + focusComposer() // after a drop, focus the message box so you can add a caption |
| } |
| func userContentController(_ controller: WKUserContentController, didReceive message: WKScriptMessage) { |
| @@ -251,8 +260,9 @@ struct ChatFeedWebView: NSViewRepresentable { |
| panel.canChooseFiles = true |
| panel.canChooseDirectories = parameters.allowsDirectories |
| panel.allowsMultipleSelection = parameters.allowsMultipleSelection |
| - panel.begin { response in |
| + panel.begin { [weak self] response in |
| completionHandler(response == .OK ? panel.urls : nil) |
| + if response == .OK { self?.focusComposer() } |
| } |
| } |
| } |