Skip to content

Add drag-and-drop support for files and folders in Local compare and Compare view - #33

Merged
svenbuild merged 14 commits into
svenbuild:mainfrom
ElektroStudios:feature/drag-and-drop-local-compare
Nov 19, 2026
Merged

svenbuild merged 14 commits into
svenbuild:mainfrom
ElektroStudios:feature/drag-and-drop-local-compare

Conversation

@ElektroStudios

@ElektroStudios ElektroStudios commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Added drag-and-drop support to both Left and Right target panes in the Local compare setup view (PickerPane.svelte):
    • Dropping a file opens its parent folder in that pane and selects the file as the target.
    • Dropping a folder navigates into that folder and selects it as the target.
  • Added drag-and-drop support to the Compare screen (CompareScreen.svelte) with a visual left/right half highlight:
    • Dropping a file or folder on the left or right half updates that side and immediately re-runs the comparison when both sides have compatible targets.
    • Dropping two files or two folders at once assigns them to the left and right sides and starts comparing immediately.
  • Reused the existing getDroppedFilePath (webUtils.getPathForFile) preload bridge and unified path selection via applyPathToPane in App.svelte.
  • Added Vitest unit tests in src/lib/app/file-drop.test.ts.
0001

Validation

  • npm run check
  • npm test
  • npm run electron:package

Notes

I have no experience with TypeScript, Svelte, or Electron, so I delegated the code implementation to an AI assistant and verified the behavior locally on Windows. Please review carefully for any idiomatic improvements or edge cases I might have missed.

- Add file-drop helper (src/lib/app/file-drop.ts) to detect OS file drag payloads, resolve dropped paths via getDroppedFilePath, and determine left/right drop targets in the compare viewer.
- Enable drag-and-drop across the entire Left and Right target panes in Local compare (PickerPane) to open parent folders and select dropped files, or open and select dropped folders.
- Enable drag-and-drop on the Compare screen (CompareScreen) with left/right drop-zone highlights, supporting single-side replacement and simultaneous two-item drops to immediately re-run local comparisons.
- Refactor shared path selection logic into applyPathToPane in App.svelte so file dialogs and drag-and-drop follow the same code path.
- Add Vitest unit tests in src/lib/app/file-drop.test.ts.
Pache Sven and others added 13 commits November 19, 2026 17:46
- One dropped item goes to the side it was dropped on, two items of the
  same kind become left and right; mixed or missing items show an error.
- On the compare screen, a single drop only replaces one side of a local
  compare. Git and GitHub compares no longer silently reload themselves
  instead of comparing the dropped items.
- Unsaved edits are confirmed before any pane state changes.
- The highlighted half and the receiving side now use the same rect, drawn
  as a fixed overlay so the compare layout is not repositioned.
- Drag tracking lives in one shared fileDropZone action.
- The main window refuses to navigate away from the app, so a drop outside
  a drop zone can no longer replace the app with the dropped file.
After a restore or a changed setup pane, a single drop could compare
against a pane target that was not the one being shown. Drops are also
ignored while the compare view is hidden under settings.
- Scroll PickerPane's virtualized entry list into view and highlight the row when pane.selectedTargetPath updates after dropping a file.
- Add findRowIndexByPath and computeRowScrollTop helpers in src/lib/app/file-drop.ts and cover them in src/lib/app/file-drop.test.ts.
…mpares

A slower drop no longer overrides a newer drop or a switch away from the
compare screen. A single folder dropped onto a multi-folder compare now
asks for two folders instead of prompting about unsaved edits first and
failing on the folder count afterwards.
…tale

The left/right split ignored the directory sidebar and side panels, so part
of the left diff counted as right. A compare started while the drop waited
for path checks or the unsaved dialog now also cancels the drop.
- Normalize forward and backward slashes when comparing dropped paths in findRowIndexByPath (src/lib/app/file-drop.ts).
- Update unit tests in src/lib/app/file-drop.test.ts to cover mixed slash formats.
… switching

A drop that waited while another compare started and finished no longer
replaces it, and an older setup drop no longer overrides a newer one. Edits
typed while the dropped folders were opening now stop the switch instead of
being lost with the old session.
A row removed under the cursor during the drag never sends dragleave, so
the highlight could stay on after the drag left.
The last merge on this branch brought back the old per-pane drag handlers
next to the shared fileDropZone action and a test for the removed
resolveCompareDropSide, so check and tests failed. The picker uses the
shared action again and keeps the new scroll-to-selected-target behavior.

- Dropped paths are no longer trimmed: on macOS and Linux a trailing
  space is part of the name.
- Row lookup only normalizes separators; names stay case sensitive.
- A drop during a running compare now explains why nothing happened.
# Conflicts:
#	src/App.svelte
#	src/lib/screens/CompareScreen.svelte
@svenbuild
svenbuild merged commit 396f09d into svenbuild:main Nov 19, 2026
2 of 5 checks passed
@svenbuild

Copy link
Copy Markdown
Owner

Thanks, merged! I reworked the drop logic before merging:

  • One dropped item goes to the side it was dropped on; two items of the same kind become left and right. Mixed or missing items show an error.
  • On the compare screen a drop used to be ignored during a Git/GitHub compare (runCompare reloaded the Git compare instead). A single drop now only replaces one side of a local compare whose other side is what is on screen; otherwise two items are needed.
  • Unsaved edits are confirmed before any pane state changes, and stale drops (newer drop, screen change, compare started meanwhile) are ignored.
  • The highlighted half and the receiving side now come from the same rect (the diff area), drawn as a fixed overlay.
  • Drag tracking lives in one shared fileDropZone action.
  • The main window now refuses to navigate away from the app. A drop outside a drop zone could otherwise replace the whole app with the dropped file.

About your two later commits: the merge 2f48129 had brought back the old per-pane drag handlers and the removed resolveCompareDropSide test, so npm run check and the tests failed. I restored the shared action and kept your scroll-to-selected-target feature. Row matching now only normalizes separators and stays case sensitive, and dropped paths are no longer trimmed: on macOS and Linux a trailing space is part of the name.

@ElektroStudios

ElektroStudios commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Note on Drag-and-Drop & Autoscroll Follow-ups (#33)

I had planned to keep refining the drag-and-drop and autoscroll behavior for #33 (Add drag-and-drop support for files and folders in Local compare and Compare view):

  • Local compare panes: accepting dropped files and folders from the OS across each target pane (getDroppedFilePath / webUtils.getPathForFile), highlighting the active drop target, opening dropped folders or opening the parent folder and selecting dropped files, and scrolling the virtualized entry list to bring newly selected dropped files into view (findRowIndexByPath and computeRowScrollTop).

Because there are already frequent commits and moving changes landing around this work, I don't have time to keep chasing every new change and re-adapting updates right now. I'll try as I can. Thank you for merging and committing changes to make it better!


Oh, I just noticed this issue has already been fixed in one of the later commits—thanks a lot! Leaving the current state here as-is.

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.

2 participants