Repository navigation
Fix SSH image drops through terminal text route #3755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
635988d
cd943f4
461c396
e8d197a
aab9918
9c50452
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2781,6 +2781,8 @@ class TerminalController { | |
| return v2Result(id: id, self.v2DebugSidebarVisible(params: params)) | ||
| case "debug.terminal.is_focused": | ||
| return v2Result(id: id, self.v2DebugIsTerminalFocused(params: params)) | ||
| case "debug.terminal.simulate_file_drop": | ||
| return v2Result(id: id, self.v2DebugSimulateTerminalFileDrop(params: params)) | ||
| case "debug.terminal.read_text": | ||
| return v2Result(id: id, self.v2DebugReadTerminalText(params: params)) | ||
| case "debug.terminal.render_stats": | ||
|
|
@@ -3017,6 +3019,7 @@ class TerminalController { | |
| "debug.right_sidebar.focus", | ||
| "debug.sidebar.visible", | ||
| "debug.terminal.is_focused", | ||
| "debug.terminal.simulate_file_drop", | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| "debug.terminal.read_text", | ||
| "debug.terminal.render_stats", | ||
| "debug.layout", | ||
|
|
@@ -12401,6 +12404,68 @@ class TerminalController { | |
| return .ok(["focused": resp.trimmingCharacters(in: .whitespacesAndNewlines).lowercased() == "true"]) | ||
| } | ||
|
|
||
| private func v2DebugSimulateTerminalFileDrop(params: [String: Any]) -> V2CallResult { | ||
| guard let tabManager else { | ||
| return .err(code: "unavailable", message: "TabManager not available", data: nil) | ||
| } | ||
| guard let surfaceId = v2String(params, "surface_id") else { | ||
| return .err(code: "invalid_params", message: "Missing surface_id", data: nil) | ||
| } | ||
| guard let rawPaths = params["paths"] as? [String] else { | ||
| return .err(code: "invalid_params", message: "Missing paths", data: nil) | ||
| } | ||
| let paths = rawPaths | ||
| .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) } | ||
| .filter { !$0.isEmpty } | ||
| guard !paths.isEmpty else { | ||
| return .err(code: "invalid_params", message: "paths must not be empty", data: nil) | ||
| } | ||
|
|
||
| let route = (v2String(params, "route") ?? "text_destination") | ||
| .trimmingCharacters(in: .whitespacesAndNewlines) | ||
| .lowercased() | ||
|
|
||
| var result: V2CallResult = .err(code: "not_found", message: "Terminal surface not found", data: [ | ||
| "surface_id": surfaceId | ||
| ]) | ||
| v2MainSync { | ||
| guard let panel = resolveTerminalPanel(from: surfaceId, tabManager: tabManager) else { | ||
| return | ||
| } | ||
|
|
||
| switch route { | ||
| case "terminal", "direct": | ||
| let handled = panel.hostedView.debugSimulateFileDrop(paths: paths) | ||
| result = handled | ||
| ? .ok(["handled": true, "route": "terminal"]) | ||
| : .err(code: "internal_error", message: "Terminal drop simulation failed", data: nil) | ||
| case "text", "text_destination", "pane_text": | ||
| guard let workspace = tabManager.tabs.first(where: { $0.id == panel.workspaceId }) else { | ||
| result = .err(code: "not_found", message: "Workspace not found", data: [ | ||
| "workspace_id": panel.workspaceId.uuidString | ||
| ]) | ||
| return | ||
| } | ||
| let urls = paths.map { URL(fileURLWithPath: $0).standardizedFileURL } | ||
| let handled = FileDropTextDropController.performTerminalTextDrop( | ||
| workspace: workspace, | ||
| panelId: panel.id, | ||
| hostedView: panel.hostedView, | ||
| urls: urls, | ||
| window: panel.hostedView.window | ||
| ) | ||
| result = handled | ||
| ? .ok(["handled": true, "route": "text_destination"]) | ||
| : .err(code: "internal_error", message: "Text destination drop simulation failed", data: nil) | ||
| default: | ||
| result = .err(code: "invalid_params", message: "Unknown route", data: [ | ||
| "route": route | ||
| ]) | ||
| } | ||
| } | ||
|
Comment on lines
+12451
to
+12481
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The Rule Used: Flag Swift fixes that patch symptoms while leaving... (source)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in e8d197a by routing overlay terminal drops through FileDropTextDropController.performTerminalFileDrop, so pane, overlay, and debug text-destination drops use the shared terminal file-drop helper and focus path. — Claude Code
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| return result | ||
| } | ||
|
|
||
| private func v2DebugReadTerminalText(params: [String: Any]) -> V2CallResult { | ||
| let surfaceArg = v2String(params, "surface_id") ?? "" | ||
| let resp = readTerminalText(surfaceArg) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
performTerminalTextDropis a function insideFileDropTextDropController(all about text drops), but its closure now callshostedView.handleDroppedURLs(urls), which routes through the full SSH-awareexecutePreparedImageTransferplanner — not text insertion. A future engineer reading the name "TextDrop" will assume this path is limited to text insertion and may incorrectly bypass it for binary/image files, or wire another caller throughhandleDroppedURLsAsTextinstead. The name should reflect the actual invariant (e.g.,performTerminalFileDroporperformSSHAwareTerminalDrop).Rule Used: Flag Swift fixes that patch symptoms while leaving... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in e8d197a by renaming performTerminalTextDrop to performTerminalFileDrop so the helper name matches the SSH-aware file upload behavior.
— Claude Code