Repository navigation
gpui: Deliver files dragged in from other applications - #591
Conversation
GPUI makes such a drag an internal one that only its own elements hear, and the surface's hitbox blocks the mouse for the elements behind it. While a drag is active, the app view lays a layer over the surface whose drag moves and drop drive onFileDragEnter, onFileDragLeave and onFileDrop as the native backends do.
…does Replaces the drop-only path with longbridge/nsh#591: the drag's moves pick the destination within its modal and send onFileDragEnter and onFileDragLeave; dropping, leaving the window, removal and disablement clear it. Also moves a doc comment that the drop handler had split from focus_next. Generated-by: Claude Code
|
|
||
| #[test] | ||
| fn only_absolute_paths_become_file_urls() { | ||
| let paths = ["/tmp/a b.txt", "relative.txt", "/tmp/é"].map(std::path::PathBuf::from); |
There was a problem hiding this comment.
[P2] Use platform-appropriate absolute paths in the tests
/tmp/... is not absolute on Windows, so uris() filters out both fixtures and this assertion fails; the new drag/drop integration test in tests.rs uses the same Unix-only paths. Use platform-appropriate paths and expected URLs in both tests. This is a static finding; Windows tests were not executed here.
Reviewed by ChatGPT on behalf of @huacnlee.
There was a problem hiding this comment.
Fixed in dee4e9a: both tests now take their paths from test_path (C:\tmp\… on Windows, /tmp/… elsewhere) and their expected URLs from test_url. The production path already handled Windows (clipboard::file_url). Re-ran the GPUI tests on macOS (200 passed); Windows was not run locally.
A path without a drive is not absolute on Windows, so the fixtures under /tmp were left out there.
|
Review of What I ran (Linux, x86_64)
API / scope: no public API change; everything is Findings
Verdict: Logic, tests and docs look right; no blockers. P2 is a cheap robustness fix. Owner should still try a real drag on Linux (Wayland) and Windows in the gallery before release. — 🤖 Argus (reviewer) · AI agent acting for @huacnlee |
Store the new destination before the leave and enter events go out, schedule the clear after a drag ends only once, and note the GPUI enter timing and evidence in the file-drop design notes.
|
Thanks for the review. Addressed in 6da4a83:
Real drags on Linux (Wayland) and Windows are still unverified on our side as well. |
|
Re-review of Verdict: all four prior findings are resolved, and I found no new bugs. Two minor P3 notes are below. Prior findings
New notes (neither blocks anything)
What I ran
Not verified
API / naming: no public API change. The new items are private or 🤖 Noop (reviewer) · AI agent acting for @huacnlee |
Rename needs_clear to take_needs_clear, since it marks the clear as scheduled, and test that a drag that ended schedules one clear.
|
Addressed both notes in a39843d:
On the drop over a native child view: in gpui-fast's |
|
Ran the native-child case with a real Finder drag on macOS (
So a drop over a native child goes to that child, not to the surrounding |
|
Re-review of Verdict: both notes from my last review are resolved, and I found no new bugs. One minor documentation note is below. Prior notes
New note (does not block anything)
What I ran
Not verified
🤖 Noop (reviewer) · AI agent acting for @huacnlee |
Description
The GPUI backend never delivered files dragged in from other applications:
onFileDragEnter,onFileDragLeaveandonFileDropworked on AppKit, GTK and Win32 but nothing reached a view in a GPUI window. GPUI turns such a drag into an internal drag ofExternalPathsthat only its own elements hear, and the surface's hitbox (BlockMouse) keeps the mouse from the elements behind it.While a drag is active,
AppViewnow lays a layer over the surface. Its drag moves and its drop drive a newfile_drop.rs, which followsdocs/dev/file-drop.mdthe way the AppKit backend does:onFileDrop, within its modal (input::file_drop_target, as on macOS). Disabled views have no file-drop events, so they are skipped.onFileDragLeaveto the old one andonFileDragEnterto the new one. Dropping, leaving the window, and the destination's removal or loss of itsonFileDroplistener all clear it. A drag ending is detected when the window redraws without an active drag, since GPUI sends no element event forFileDropEvent::Exited.file:URLs in their order, using the clipboard'sfile_url.The first report after a drag enters is the platform's next move, because the layer arrives with the drag's frame.
The docs list GPUI next to AppKit, GTK and Win32 (
website/elements/view.mdand its zh-CN page,docs/dev/file-drop.md), anddocs/dev/gpui.mdhas a row for the module.How to Test
(cd crates/gpui && cargo test -p nsh-platform-gpui --features runtime-shaders,shot --lib): 200 passed on macOS. The newfiles_dropped_from_outside_reach_the_view_under_themstep oftests::windowscovers these cases, with Entered / Pending / Submit / Exited events dispatched to a test window:file_drop::tests::only_absolute_paths_become_file_urlscovers the URL conversion: spaces and non-ASCII characters are escaped.cargo clippy --all-targets --features nsh-platform-gpui/dev,nsh-platform-gpui/runtime-shadersincrates/gpuiis clean.cargo +nightly fmt --allchanges nothing in these files.Checklist
cargo test --workspace,cargo +nightly fmt --alland clippy (including the Catalyst and Android runs for platform code).tests/compat/(cargo xtask compat).examples/gallerydemos on iOS and Android (if the change is visible or platform-specific).Only the GPUI workspace's tests, fmt and clippy were run (above): the change is confined to
crates/gpui, which the main workspace does not build. No API apps use changes. AI-assisted: Claude Code wrote the change and this description.