Repository navigation
terminal: add drag-and-drop support - #101
Conversation
vaayne
left a comment
There was a problem hiding this comment.
Thanks for adding this — the overall approach and test coverage look solid. I found two edge cases worth addressing before merge.
| return TerminalShell.escape(url) | ||
| } | ||
|
|
||
| let strings = (pasteboardItems ?? []).compactMap { item in |
There was a problem hiding this comment.
This per-item fallback differs from Ghostty’s actual drag-and-drop precedence. In vendored Ghostty, SurfaceView_AppKit.performDragOperation checks the whole pasteboard in order: .URL, then all NSURL objects, then .string. If any file URL exists, plain-string items are not appended. Here, dragging a file plus a separate string produces /path/to/file describe this, and the new mixed-item test locks in that divergence. Could we mirror performDragOperation’s global branching here and update the test? (Ghostty’s getOpinionatedStringContents() does use per-item fallback, but that helper is not used by its drag path.)
|
|
||
| private enum TerminalShell { | ||
| // Match Ghostty's shell-sensitive character set for terminal insertion. | ||
| private static let escapeCharacters = "\\ ()[]{}<>\"'`!#$&;|*?\t" |
There was a problem hiding this comment.
Please reject file paths containing CR or LF before inserting them. macOS filenames can contain newlines, and this escape set leaves them untouched. The path then reaches ghostty_surface_text; libghostty treats that as an already-confirmed paste, and when bracketed paste is disabled it converts LF to CR. A maliciously named dropped file can therefore submit subsequent lines as terminal commands without another Enter. Ghostty currently shares this escape set, but this PR makes the path reachable in Mori. The smallest safe fix is to return nil for file paths containing \r or \n and add a regression test.
Both sides added test targets and changelog sections independently: - mise.toml/AGENTS.md: keep test:terminal (ours) and test:git + test:ui (theirs) - CHANGELOG*: keep the drag-and-drop Features entry, adopt the renamed Design section heading from main
Inspect the pasteboard as a whole (URL, else all file URLs, else string) instead of falling back per item, so a file plus a string no longer inserts both — this mirrors Ghostty's performDragOperation. Reject file paths containing CR/LF: the shell escape set leaves them untouched, and libghostty treats inserted text as a confirmed paste (converting LF to CR when bracketed paste is off), so a maliciously named file could submit the rest of the value as a command. One unsafe path rejects the whole drop rather than silently omitting a file.
Dragging files (or URLs/text) onto a Mori terminal pane currently does nothing —
GhosttySurfaceViewnever registers for dragged types, so AppKit discards the drop before any bytes reach the terminal.This PR adds drag-and-drop to the Ghostty surface, mirroring upstream Ghostty's macOS
SurfaceViewimplementation:.URL,.fileURL, and.stringpasteboard types and answers.copyfor supported dragsinsertTexton the main queue after the drag session ends, so content flows throughghostty_surface_text, which libghostty treats with paste semantics (bracketed paste when the pty enables it)That last point means drops behave like pastes end to end: TUIs inside Mori's tmux sessions (pi, Claude Code, …) receive a real bracketed paste and can attach a dropped image instead of seeing raw keystrokes. Complements the remote-image request in #51 for the local case.
Testing
MoriTerminalTestsexecutable target (following the repo's non-XCTest convention), wired asmise run test:terminaland into the aggregate suite: drag-type registration, URL/file/string precedence, percent-decoding, shell escaping (spaces, parentheses), multi-item ordering.swift build --product Moriandswift run MoriTerminalTestspass.CHANGELOG and README entries added in both languages per repo conventions.
i hope this change is acceptable, it works on my end and solved a big problem for me, i used claude fable to implement the fix, apologies if this is an annoying slop pr