Skip to content

feat(sftp): support drag-and-drop move in SFTP and local file browsers - #1321

Merged
t8y2 merged 1 commit into
t8y2:mainfrom
DeanCen:feat/file-browser-drag-move
Nov 24, 2026
Merged

t8y2 merged 1 commit into
t8y2:mainfrom
DeanCen:feat/file-browser-drag-move

Conversation

@DeanCen

@DeanCen DeanCen commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Closes #1282

Summary

Adds drag-and-drop move support for files and folders across both SFTP and local file browsing surfaces:

  • Docked file browser (SSH SFTP panel, local side toggle, and local terminal file browser)
    • Drag single or multi-selected files and folders onto subfolder rows in the file list or onto ancestor breadcrumbs in the address bar.
    • Shows a floating drag badge, folder-row drop overlay (Drop here to move), and translucent breadcrumb highlight; pressing Esc cancels an active drag.
  • Standalone / tabbed dual-pane SFTP window (sftpWindow)
    • Supports same-side drag-and-drop move (remote → remote and local → local) onto subfolder rows, same-side directory tree nodes, and ancestor breadcrumbs, while keeping existing cross-pane upload/download and cross-window/tab transfer behavior unchanged.
    • Refreshes affected directory tree nodes after a move completes.
  • Validation & safety
    • Rejects no-op same-directory drops and moving a non-symlink directory into itself or any of its descendants.
    • Remote moves reuse the SFTP worker's Rename / MoveSelection operations; local moves run asynchronously via os.Rename with destination collision checks so existing files are never silently overwritten.
  • Localization
    • Adds DropMoveHint in English, Simplified Chinese, and Traditional Chinese.

Verification

  • Added tests in internal/workbench/sftp_drag_move_test.go covering path validation, docked SFTP remote drag-move (single, multi-select, self-drop rejection, Esc cancel, breadcrumb drop), docked local terminal drag-move (file, folder, collision protection, breadcrumb drop), and dual-pane SFTP window same-side drag-move (remote row, local row, directory tree node).
  • Ran go test ./internal/i18n ./internal/sftpclient, SFTP/local/selection tests in ./internal/workbench, go vet ./internal/i18n ./internal/workbench, and go build ./....
  • Verified manually in a Windows dev build.

@t8y2 t8y2 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the work on this. Three items block merge:

  1. In-pane drag (internal/workbench/sftp_drag_move.go:309-409, and sftp_window_input.go:402-454) reimplements press/threshold/target/drop/Esc and rect hit-testing by hand. Viva already has ui.DragState (DragSource/DropTarget, Esc cancel), and host_grid.go uses it. Please move the gesture onto it, or explain in the PR why it does not fit the reusable boundary.
  2. TestSFTPWindowSamePaneDragMoveRemoteLocalAndTree (sftp_drag_move_test.go:414) fails on the Windows CI shard with a timeout in the local same-pane move step, while it passes on Linux. Please find out whether the local rename fails on Windows (and include view.errorText in the failure message) or whether the wait is too short.
  3. internal/workbench/sftp.go:99-100 is not gofmt-formatted, which fails the Format and vet job. The branch also conflicts with main in the rename/remove case of pumpSFTP, so it needs a rebase.

@DeanCen
DeanCen force-pushed the feat/file-browser-drag-move branch from 86a14dd to de35279 Compare November 22, 2026 16:50
@DeanCen

DeanCen commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the review! All three items have been addressed in the updated commit (de35279c):

  1. Moved docked panel drag-and-drop onto Viva's ui.DragState:
    • Replaced the manual pointer/threshold/rect hit-testing/Escape plumbing in sftp_drag_move.go, sftp.go, and workbench.go with ui.DragState (Box.DragSource on list rows, Box.DropTarget on directory rows and ancestor breadcrumbs in sftp_paint.go), following host_grid.go.
    • Kept sftpWindow's same-side move on the existing sftpWindowDrag (w.drag) because a single row press in sftpWindow can transition seamlessly between same-pane move, opposite-pane upload/download, and cross-window / cross-tab transfers using screen coordinates (fileDropWindowAt / fileDragTabAt). Since ui.DragState is scoped to a single page/frame and claims the pointer once the drag threshold is crossed, putting sftpWindow rows on ui.DragState would intercept events before w.pointer and break cross-window/tab drags.
  2. Fixed Windows CI timeout in TestSFTPWindowSamePaneDragMoveRemoteLocalAndTree:
    • Line 414 was waiting for the local directory tree to finish disclosing ancestors from the drive root down to t.TempDir(), which on Windows CI can exceed 3s (matching the 20s deadline in waitDirectoryTree in sftp_directory_tree_test.go).
    • Updated waitWindowSFTP to a 20s timeout and included view.errorText, view.status, busy flags, paths, row counts, and directory tree state in the failure message.
    • Updated the docked panel drag tests to route pointer/key events through state.WindowConfig(...) so they exercise the full ui.Page + ui.DragState path.
  3. Formatting & rebase:
    • Rebased onto latest main (d36f0d34), resolved the pumpSFTP conflict in internal/workbench/sftp.go, and ran gofmt across all modified files (gofmt -l is clean and go vet + SFTP/local/i18n tests pass).

@t8y2 t8y2 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

感谢重做:docked 面板的拖拽现在走 ui.DragState,gofmt 干净,与 main 的冲突也没了,之前提的大部分问题已解决。还有一项阻塞合并:

internal/workbench/sftp_drag_move_test.go:435 的 TestSFTPWindowSamePaneDragMoveRemoteLocalAndTree 在 CI 的 Workbench (Windows, autocrlf, 1/5) 分片仍然失败,把等待加到 20s 也没用。失败信息是 status="Moved ...local_file.txt to ...local_sub\local_file.txt"、busy=false、errorText 为空,但 localRows 没变,也就是 os.Rename 已成功,列表没刷新或「行消失」的判断在 Windows 上不成立。怀疑是 finishLocalMove(sftp_drag_move.go:215-221)里按词法路径比较,t.TempDir() 的 8.3 短路径(RUNNER~1)和规范路径对不上。请在 Windows 上复现,按文件标识(os.SameFile 或 sameDirectoryTreeLocation)比较,不要靠加大超时。

不挡本 PR 的后续项:本地移动先 Lstat 目标再 os.Rename,两步之间目标被创建会被静默覆盖;拖到另一个卷上会返回 EXDEV 且没有复制再删除的回退(失败时源文件原样保留,不丢数据)。

@DeanCen
DeanCen force-pushed the feat/file-browser-drag-move branch from de35279 to bdabaab Compare November 23, 2026 16:41
@DeanCen

DeanCen commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

感谢重做:docked 面板的拖拽现在走 ui.DragState,gofmt 干净,与 main 的冲突也没了,之前提的大部分问题已解决。还有一项阻塞合并:

internal/workbench/sftp_drag_move_test.go:435 的 TestSFTPWindowSamePaneDragMoveRemoteLocalAndTree 在 CI 的 Workbench (Windows, autocrlf, 1/5) 分片仍然失败,把等待加到 20s 也没用。失败信息是 status="Moved ...local_file.txt to ...local_sub\local_file.txt"、busy=false、errorText 为空,但 localRows 没变,也就是 os.Rename 已成功,列表没刷新或「行消失」的判断在 Windows 上不成立。怀疑是 finishLocalMove(sftp_drag_move.go:215-221)里按词法路径比较,t.TempDir() 的 8.3 短路径(RUNNER~1)和规范路径对不上。请在 Windows 上复现,按文件标识(os.SameFile 或 sameDirectoryTreeLocation)比较,不要靠加大超时。

不挡本 PR 的后续项:本地移动先 Lstat 目标再 os.Rename,两步之间目标被创建会被静默覆盖;拖到另一个卷上会返回 EXDEV 且没有复制再删除的回退(失败时源文件原样保留,不丢数据)。

Thanks for the spot-on diagnosis! It was indeed the lexical path comparison failing on Windows 8.3 short paths (RUNNER~1).

The branch has been updated with file-identity comparisons:

  1. File-identity matching in sameSFTPPath: Switched local comparisons from sameDirectoryTreePath to sameDirectoryTreeLocation(true, left, right), falling back to os.SameFile when lexical comparison fails. This resolves the mismatch between canonical long paths and 8.3 short aliases across finishLocalMove, breadcrumbs, and drop target checks.
  2. Short-path ancestor traversal in isSFTPSubpath: When the lexical prefix check misses on Windows, it now walks up candidate parent directories using sameDirectoryTreeLocation, ensuring child directory checks correctly identify containment across short-name aliases.
  3. Tree node resolution in refreshDirectoryTreeNode: Updated to use directoryTreeResolveNode instead of direct map lookup, properly locating and invalidating tree nodes even when touched through an 8.3 alias.
  4. Dedicated Windows alias test: Added TestSFTPDragMoveResolvesWindowsShortPathAlias in sftp_drag_move_windows_test.go covering sameSFTPPath, isSFTPSubpath, validFileMoveTarget, and finishLocalMove auto-refresh with short vs long path aliases.
  5. All tests (TestSFTPWindowSamePaneDragMoveRemoteLocalAndTree, etc.) pass locally, and both gofmt and go vet are clean.

@t8y2
t8y2 merged commit 5806f9d into t8y2:main Nov 24, 2026
17 of 19 checks passed
@t8y2

t8y2 commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks for the contribution! Merged in 5806f9d, will be released in the next version.

@DeanCen
DeanCen deleted the feat/file-browser-drag-move branch November 24, 2026 03:59
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.

[Feature] SFTP 文件夹文件支持拖拽移动

2 participants