Skip to content

feat(app): move files and folders by dragging them in the SFTP file panel - #297

Merged
TooonyChen merged 1 commit into
mainfrom
feature/sftp-drag-move
Dec 1, 2026
Merged

TooonyChen merged 1 commit into
mainfrom
feature/sftp-drag-move

Conversation

@TooonyChen

Copy link
Copy Markdown
Owner

Summary

Rows of the SFTP file table can now be dragged onto a folder to move them there on the server, as asked in #295 ("我没办法在文件栏拖动文件,比如移动他到文件夹里。需要添加支持").

What is dragged: the row pressed, or every chosen row when the pressed row is one of them (MyGo's ListState.DragRows, as the connection manager does since #239). A row that is not chosen drags alone and the choice is left as it is. With a search open, rows the search hides are already unchosen (#276), so only shown rows move; with a sort (#272) the drag goes by name, not by row index. A press and release without moving is still a click, and the header does not drag rows.

Drop targets, outlined while a valid drag is over them, with a note at the bottom of the table ("Drop to move to /opt/magpie"):

  • a folder row of the table, including a link to a folder (it moves into the folder the link points to, which is what opening that row does). Every cell of a folder row takes the drop: the cell content fills the cell, padding included, and the whole row is outlined from the next frame on, since only the cell under the pointer is told about the drag.
  • a folder in the folder tree, including folders outside the current one;
  • the up button and the breadcrumbs of the path bar (feat(app): add optional breadcrumbs to the SFTP path bar #223), for folders above.

Refused or no-op drops show no outline and do nothing: the rows' own folder, a dragged row itself, a folder into itself or a folder inside it, another session's panel, no SFTP connection. While a move runs nothing can be dragged (DragRows returns nil and targets refuse), so a second drag cannot overlap a running move; the toolbar shows the spinner meanwhile.

The move itself is a new remotefs.Move(c, from, names, to, replace) next to Rename, run in a goroutine with the result posted through App.post and dropped when the session's SFTP client changed. Like Rename it looks before it moves and never replaces silently:

  • a folder never goes into itself or a descendant; this is checked on the paths and also with both folders resolved through symbolic links (by walking the path with Lstat/ReadLink, because some servers' realpath, including pkg/sftp's, does not resolve links);
  • into the folder the items are already in (also through a link), nothing happens;
  • a name taken by a file, when the moved item is a file or link, is an ExistsError. The panel then asks with the existing upload question ("Replace existing items?"); Replace uses OpenSSH's posix-rename, Cancel leaves both files untouched;
  • a name where either side is a folder is a FolderExistsError: folders are never merged, and a file and a folder never replace each other (the issue's recommendation). It is reported rather than asked.

Items whose names are free move at once, before the question; only the conflicting ones wait for the answer. This avoids a check-then-act gap and matches Explorer. When some items fail (folder conflict, permission denied, a server refusing a cross-device rename, an item gone since it was listed), a dialog lists each with its reason and says how many others were moved; those stay moved. The replace question got an optional no callback so that failures are still reported after Cancel.

Afterwards the current folder is listed again, the source and target folders are re-read in the tree if loaded, and the tree's open/loaded state of a moved folder follows it (the rename code's tree bookkeeping became fileState.treeMoved, shared by both). Moved rows disappear from the selection; the rest of the selection stays.

OS file drops still upload: the new targets take only in-app values (ui.Drop[*fileMoveDrag]), so files from Finder/Explorer still reach the table and tree drop zones, and an in-app drag never shows the "Drop to upload" note.

Where this deviates from or settles the issue:

  • Cancel on the conflict question leaves the conflicting items in place, but items without a conflict have already moved (see above).
  • Keyboard: Rename does not take a path, so the docs say moving needs dragging and suggest mv in the terminal.
  • Dropping on a link to a folder is allowed, as opening it follows the link.

Docs: a "Moving by dragging" section in docs/en/features.md and docs/zh-CN/features.md, and one clause in the Files paragraph of both READMEs. New strings in locales/en.json and locales/zh-Hans.json, catalog_gen.go regenerated. go run ./tools/screenshots leaves docs/screenshots/ unchanged.

Closes #295

Testing

  • go build ./..., go vet ./..., GOOS=windows go vet ., GOOS=darwin go vet ., go tool mygo vet, gofmt
  • go test -race -count=1 -timeout 30m ./... (see note below)
  • New tests, against the in-process SFTP server, driving real drags through the headless tester (press, pointer moves, release):
    • TestMove (internal/remotefs): move into another folder, no-op into the own folder directly or through a link, refused into itself or a descendant (also through a link), taken name refused then replaced, file over folder and folder over folder refused with replace, links moved as links, bad names.
    • TestFileMoveToFolderRow: one row and three chosen rows (chosen by click and Cmd-click, including a folder) onto a folder row; files' new places, listing, tree, selection; the hint while over; OS file drop on a folder row still uploads; click and double-click to open still work.
    • TestFileMoveToTree: onto a tree folder outside the current folder, a folder moved and the tree updated, onto the up button, onto a breadcrumb.
    • TestFileMoveRefused: onto itself, file onto file, folder into its own subfolder in the tree, onto its own folder, a header dragged onto a folder, no drag without SFTP or during a move, another session's panel.
    • TestFileMoveConflict: question shown, Cancel leaves both, Replace replaces while a free name moved at once, folder-over-folder reported with the other item moved, an item deleted on the server meanwhile reported while the other moved, OK and Escape close the report.
    • TestFileMoveSearchSort: with a search hiding a chosen row and a size sort, only the shown chosen rows move.
  • Not tested: real drags on Windows, macOS and Linux desktops (only the headless tester runs here), and a real OpenSSH server (posix-rename and permission errors come from the in-process pkg/sftp server).

Generated by Claude Code

…anel

Rows of the file table drag onto a folder row, a folder of the tree,
the up button or a breadcrumb, which moves them there with an SFTP
rename (remotefs.Move). A taken file name asks before replacing,
folders are never merged or replaced, and items that could not move
are reported with the reason while the others stay moved.

Closes #295

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015nMqJEvqPnRmPgi6dnraZM
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-01T23:11:22.547658Z 4feb200 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@TooonyChen
TooonyChen merged commit 00d4a3e into main Dec 1, 2026
1 check passed
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.

feat(app): move files and folders by dragging them in the SFTP file panel

2 participants