Skip to content

fix: move a task instead of duplicating it when dragged between notes#889

Open
RIDAM7 wants to merge 1 commit into
team-reflect:masterfrom
RIDAM7:fix/task-dnd-duplicate-across-notes
Open

fix: move a task instead of duplicating it when dragged between notes#889
RIDAM7 wants to merge 1 commit into
team-reflect:masterfrom
RIDAM7:fix/task-dnd-duplicate-across-notes

Conversation

@RIDAM7

@RIDAM7 RIDAM7 commented Jul 18, 2026

Copy link
Copy Markdown

Fixes #747

Problem

The daily stream mounts one ProseMirror EditorView per day, so dragging a task
from one day onto another is a drag between two editor instances. ProseMirror
only deletes dragged content in the view where the drop lands, so the target
inserted a copy while the source kept the original — the task ended up in both notes.

Fix

The block-handle grip is a floating element outside any view.dom, so this adds a
document-level bridge (cross-note-drag-move.tsx) that tracks the mounted note
views, and on the source view's dragend — when the drop landed in a different
editor and it was a move — runs the delete ProseMirror skipped, using PM's own drag
record (dragging.node.replace, the same call a same-view move uses). A cancelled
drop or a copy drag deletes nothing, so neither can lose the original.

The move decision is factored into a pure crossNoteMoveDeletion helper with unit
tests. Native drag-and-drop can't run under vitest/jsdom, so the gesture itself was
verified manually in the running app; the automated coverage is the decision logic.

Testing

  • pnpm typecheck, pnpm lint, pnpm test pass
  • Manually verified in pnpm tauri:dev: dragging a task between daily notes now
    moves it to a single note; a drop cancelled mid-drag leaves the original intact.

Summary by CodeRabbit

  • New Features

    • Added support for moving content between note editors using drag and drop.
    • Source content is automatically removed after a successful cross-note move.
    • Copy operations, cancelled drops, same-editor moves, and empty selections remain unchanged.
  • Tests

    • Added coverage for cross-editor moves, copies, cancellations, and selection handling.

Each day in the daily stream is a separate ProseMirror EditorView, so dragging a task from one day to another is a cross-view drag. ProseMirror only deletes the dragged content in the view where the drop lands, so a cross-view move inserted a copy in the target while leaving the original in the source, and the task appeared in both notes.

Add a document-level bridge that coordinates the mounted note views and completes the move by deleting the source node ProseMirror skipped, gated so a cancelled or copy drag loses nothing.

Fixes team-reflect#747
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e3b0c84b-c8e8-48bd-ad3f-eb1eb41c9c07

📥 Commits

Reviewing files that changed from the base of the PR and between cab03fb and aff9a12.

📒 Files selected for processing (3)
  • apps/desktop/src/editor/cross-note-drag-move.test.ts
  • apps/desktop/src/editor/cross-note-drag-move.tsx
  • apps/desktop/src/editor/note-editor.tsx

Walkthrough

Adds cross-editor drag-move handling to desktop note editors. Document listeners track drag sources and drop targets, then delete moved nodes or selections from the source editor while preserving copies, same-editor drags, and cancelled drops.

Changes

Cross-note drag move

Layer / File(s) Summary
Deletion decision contract
apps/desktop/src/editor/cross-note-drag-move.tsx, apps/desktop/src/editor/cross-note-drag-move.test.ts
Defines CrossNoteMoveDeletion and tests node, selection, copy, same-editor, cancelled-drop, target-view, and empty-selection cases.
Cross-editor drag completion
apps/desktop/src/editor/cross-note-drag-move.tsx
Tracks drag source and drop target views, detects accepted cross-editor moves, deletes source nodes or selections, and dispatches the resulting transaction.
Editor lifecycle wiring
apps/desktop/src/editor/cross-note-drag-move.tsx, apps/desktop/src/editor/note-editor.tsx
Registers mounted editor views, reference-counts document listeners, clears stale references on unmount, and renders CrossNoteDragMove in MeowdownEditor.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Source editor
  participant CrossNoteDragMove
  participant Target editor
  Source editor->>CrossNoteDragMove: dragstart
  Target editor->>CrossNoteDragMove: accepted drop
  CrossNoteDragMove->>Source editor: delete moved node or selection
  CrossNoteDragMove->>Source editor: dispatch drop transaction
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: dragging a task between notes now moves it instead of duplicating it.
Linked Issues check ✅ Passed The changes address #747 by deleting the source content on cross-note move, preventing duplicate task items.
Out of Scope Changes check ✅ Passed The added tests and editor bridge are directly related to the cross-note drag/move fix and do not appear unrelated.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@RIDAM7

RIDAM7 commented Jul 18, 2026

Copy link
Copy Markdown
Author

This is Screen Recording after fix #747.

Fix.747.Screen.Recording.mp4

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.

Drag and drop a task from one note to another should not duplicate the task item.

1 participant