Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Sources/DragOverlayRoutingPolicy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,25 @@ enum FileDropTextDropController {
return true
}

@discardableResult
static func performTerminalTextDrop(
workspace: Workspace,
panelId: UUID,
hostedView: GhosttySurfaceScrollView,
urls: [URL],
window: NSWindow?
) -> Bool {
performPanelTextDrop(
workspace: workspace,
panelId: panelId,
focusIntent: .terminal(.surface),
window: window,
insert: {
hostedView.handleDroppedURLs(urls)
}
)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Misleading abstraction name on the new helper

performTerminalTextDrop is a function inside FileDropTextDropController (all about text drops), but its closure now calls hostedView.handleDroppedURLs(urls), which routes through the full SSH-aware executePreparedImageTransfer planner — 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 through handleDroppedURLsAsText instead. The name should reflect the actual invariant (e.g., performTerminalFileDrop or performSSHAwareTerminalDrop).

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!

Copy link
Copy Markdown
Contributor Author

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


static func focusPanelAfterSuccessfulTextDrop(
workspace: Workspace,
panelId: UUID,
Expand Down
6 changes: 3 additions & 3 deletions Sources/FileDropOverlayViewHitTesting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ extension FileDropOverlayView {
func performFileDropAsText(_ sender: any NSDraggingInfo) -> Bool {
let urls = DragOverlayRoutingPolicy.fileURLs(from: sender.draggingPasteboard)
guard !urls.isEmpty else { return false }
let text = TerminalImageTransferPlanner.insertedText(forFileURLs: urls)
guard !text.isEmpty else { return false }

let windowPoint = sender.draggingLocation
if let textView = editableTextViewUnderPoint(windowPoint) {
let text = TerminalImageTransferPlanner.insertedText(forFileURLs: urls)
guard !text.isEmpty else { return false }
return insert(text, into: textView)
}
if let terminal = terminalUnderPoint(windowPoint) {
Expand Down Expand Up @@ -214,7 +214,7 @@ extension FileDropOverlayView {
}

private func insert(_ urls: [URL], into terminal: GhosttyNSView) -> Bool {
let handled = terminal.handleDroppedFileURLsAsText(urls)
let handled = terminal.handleDroppedFileURLs(urls)
guard handled,
let workspaceId = terminal.tabId,
let terminalSurfaceId = terminal.terminalSurface?.id,
Expand Down
2 changes: 1 addition & 1 deletion Sources/GhosttyTerminalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9334,7 +9334,7 @@ class GhosttyNSView: NSView, NSUserInterfaceValidations {
}
}

fileprivate func handleDroppedFileURLs(_ urls: [URL]) -> Bool {
func handleDroppedFileURLs(_ urls: [URL]) -> Bool {
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
executePreparedImageTransfer(
.fileURLs(urls),
onCancel: {}
Expand Down
65 changes: 65 additions & 0 deletions Sources/TerminalController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -3017,6 +3019,7 @@ class TerminalController {
"debug.right_sidebar.focus",
"debug.sidebar.visible",
"debug.terminal.is_focused",
"debug.terminal.simulate_file_drop",
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
"debug.terminal.read_text",
"debug.terminal.render_stats",
"debug.layout",
Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Dual wiring of terminal-drop behaviour remains after this PR

The text_destination branch calls FileDropTextDropController.performTerminalTextDrop (which goes through hostedView.handleDroppedURLs → surfaceView.handleDroppedFileURLs), while FileDropOverlayViewHitTesting.insert(_:into:) calls terminal.handleDroppedFileURLs directly with its own separate focus-management block. Both paths invoke the SSH-aware planner, but they arrive there through independent wrappers with independent focus side-effects. If focus logic is updated in one path it must also be kept in sync with the other; the last pre-PR regression was caused by exactly this kind of divergence. The architectural fix would be a single shared entry point that owns both the planner dispatch and the subsequent focus transition — the new performTerminalTextDrop is a step in the right direction, but the FileDropOverlayViewHitTesting path does not yet use it.

Rule Used: Flag Swift fixes that patch symptoms while leaving... (source)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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

Comment thread
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)
Expand Down
20 changes: 8 additions & 12 deletions Sources/TerminalPaneDropTargetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,12 @@ final class PaneDropTargetView: NSView {
workspace: Workspace
) -> Bool {
if let hostedView {
return FileDropTextDropController.performPanelTextDrop(
return FileDropTextDropController.performTerminalTextDrop(
workspace: workspace,
panelId: context.panelId,
focusIntent: .terminal(.surface),
window: window,
insert: {
hostedView.handleDroppedURLsAsText(urls)
}
hostedView: hostedView,
urls: urls,
window: window
)
}

Expand All @@ -291,14 +289,12 @@ final class PaneDropTargetView: NSView {
return false
}
if let terminalPanel = panel as? TerminalPanel {
return FileDropTextDropController.performPanelTextDrop(
return FileDropTextDropController.performTerminalTextDrop(
workspace: workspace,
panelId: panelId,
focusIntent: .terminal(.surface),
window: window ?? terminalPanel.hostedView.window,
insert: {
terminalPanel.hostedView.handleDroppedURLsAsText(urls)
}
hostedView: terminalPanel.hostedView,
urls: urls,
window: window ?? terminalPanel.hostedView.window
)
}
if let filePreviewPanel = panel as? FilePreviewPanel {
Expand Down
13 changes: 13 additions & 0 deletions tests_v2/cmux.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,19 @@ def is_terminal_focused(self, panel: Union[str, int]) -> bool:
res = self._call("debug.terminal.is_focused", {"surface_id": sid}) or {}
return bool(res.get("focused"))

def simulate_terminal_file_drop(
self,
panel: Union[str, int],
paths: list[str],
route: str = "text_destination",
) -> None:
sid = self._resolve_surface_id(panel)
self._call(
"debug.terminal.simulate_file_drop",
{"surface_id": sid, "paths": [str(path) for path in paths], "route": route},
timeout_s=30.0,
)

def read_terminal_text(self, panel: Union[str, int, None] = None) -> str:
params: Dict[str, Any] = {}
if panel is not None:
Expand Down
Loading
Loading