Skip to content

feat(desktop): drag files from the file tree into other Windows apps - #65330

Open
Hona wants to merge 3 commits into
devfrom
file-drag-out
Open

Hona wants to merge 3 commits into
devfrom
file-drag-out

Conversation

@Hona

@Hona Hona commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Issue for this PR

No linked issue. Ported from the native Rune desktop build (anomalyco/rune-desktop, features/open-in/src/lib.rs drag_item, and Rune's crates/rune/src/drag_out/windows.rs).

Type of change

  • New feature

What does this PR do?

On Windows, a file or folder dragged from the file tree now drops into other apps as the file itself: File Explorer copies it, a browser uploads it, a chat app attaches it. Today the drag carries only text, so other apps get nothing or a file: string.

A drop back into the composer still adds an @ mention, as it does today.

How it works:

  • The tree sets its drag data as before, then calls a new built-in host API, desktop.dragOut(event, path), with the row's absolute path. The tree calls it only for a session on a local server (the same check as Open in).
  • On Windows desktop the host cancels the page's drag and asks main for a system drag (FilesStartDrag). Main checks that the path is absolute and exists, then calls webContents.startDrag with the file's shell icon.
  • The host keeps the page drag's text/plain until main answers that the drag ended. A drop into the composer whose single file is that path reads as that text, so it becomes the same mention. While the drag is out, the composer shows its mention drop state, not the attachment one.

Only Windows changes. The desktop platform defines startFileDrag only when os === "windows", and main's startDrag returns false unless process.platform === "win32". Elsewhere dragOut returns false and the tree's own drag goes on, so macOS, Linux and the web are unchanged.

dragOut is on BuiltinDesktop (@opencode/plugin/gui/builtin), not the public SDK.

How did you verify your code works?

  • src/runtime/platform/drag-out.test.ts in packages/app (2 pass, new):
    • with a system drag, dragstart is cancelled, and only a drop of that one file reads as the row's text, until the drag ends;
    • without one, the row keeps its own drag.
  • src/composer/attachments in packages/app (6 pass), bun test src/file in packages/gui-plugins (195 pass).
  • bun typecheck in packages/plugin, packages/app and packages/gui-plugins, bun run typecheck:tsc in packages/desktop, bun script/sdk-docs.ts and bun run lint:changed origin/dev clean.
  • Not tested: a real drag to File Explorer, a browser or back into the composer. That needs a mouse on a visible desktop. The mention on a drop back relies on Windows' startDrag returning only after the drop, which is how Electron's Windows implementation reads. If it returned sooner, such a drop would add the file as an attachment instead.

Screenshots / recordings

Not captured: needs a visible desktop.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Public API: adds dragOut(event, path) to BuiltinDesktop in @opencode/plugin/gui/builtin, not the public SDK (backwards compatible)

@opencodejr opencodejr Bot left a comment

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.

I couldn't verify this end to end. The feature only runs on Windows desktop and needs a real mouse drag into another app. The new drag-out.test.ts passes, bun test src/file in packages/gui-plugins passes (195 tests), and tsc -b is clean in packages/app, packages/gui-plugins, packages/plugin and packages/desktop. When you try it on Windows, please also check that the dragged row doesn't stay dimmed afterwards (see the inline comment on pierre-tree.tsx).

Public API: the only addition is dragOut(event, path) on BuiltinDesktop (@opencode/plugin/gui/builtin). That isn't the public SDK, and it's backwards compatible. The desktop FilesStartDrag call and the startFileDrag additions on the platform and renderer APIs are internal.

Concerns:

  • Likely bug: the tree library's internal drag never ends after a drag-out, so the dragged row probably stays at half opacity (inline on pierre-tree.tsx).
  • Smaller risk: a drop back into the composer becomes a mention only on an exact path match, so a slash or drive-letter difference would turn it into an attachment (inline on drag-out.ts).

@opencodejr opencodejr Bot left a comment

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.

The new commits fix both earlier points. When the system drag ends, the tree now gets the dragend its cancelled drag never fired. That event reaches the tree library's window dragend listener, which ends its drag session, so the dragged row should no longer stay dimmed. Drops back into the composer now match the path ignoring case and slash direction. The updated drag-out.test.ts passes (2 tests), bun test src/file in packages/gui-plugins passes (195 tests), and tsc -b is clean in packages/app, packages/gui-plugins and packages/desktop.

I still couldn't run a real drag: that needs Windows desktop and a mouse. When you try it on Windows, please check that the dragged row returns to normal after dropping into Explorer, and that a drop back into the composer adds an @ mention.

Public API: unchanged since my last review. The only addition is BuiltinDesktop.dragOut (@opencode/plugin/gui/builtin); its doc now says the event's target gets a dragend when the system drag ends. It's backwards compatible.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant