Skip to content

Drag and drop asks before replacing data (fixes #3136) - #3216

Merged
h-a-n-a-s-h-i merged 3 commits into
storytold:mainfrom
hectorviov:fix/drag-move-replace-prompt
Nov 3, 2026
Merged

h-a-n-a-s-h-i merged 3 commits into
storytold:mainfrom
hectorviov:fix/drag-move-replace-prompt

Conversation

@hectorviov

@hectorviov hectorviov commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3136

What

Dragging a selection by its border onto cells that hold data replaced them without asking, so dragging column B onto column A silently destroyed column A. Excel asks first: "There's already data here. Do you want to replace it?" (its Alert before overwriting cells option, on by default). GridCraft now asks the same question, with OK and Cancel.

  • New engine command range.move {range?, to, overwrite?} (label "Drag and Drop", one undo step): the same cut and paste the drop ran before, but when the destination holds content outside the moved cells it returns a confirm question (EngineError::Confirm) instead of moving. overwrite: true goes ahead. A refused or failed move leaves the sheet and the clipboard as they were (a copy made earlier keeps its marching ants).
  • The grid's drop (crates/ui-egui/src/grid/interact.rs) runs range.move through macro_ui::call, so the existing question box shows the question; OK runs it again with overwrite: true, Cancel does nothing.
  • Dropping onto empty cells, or onto cells that overlap only the moved cells themselves (moving A1:A3 down one row), still moves without a question, as in Excel.
  • docs/ui-parity.md: the drag-move row claimed Ctrl/Option copy and Shift insert were done for the border drag; they are not wired (the drop ignores modifiers), so the row now says so, plus a revision row.

Comparison

Synthetic workbook: A1:B3 = Apple/Kiwi, Pear/Plum, Fig/Lime. Select column B, drag its border onto column A.

GridCraft main (178f3eb) GridCraft with this PR Excel (Microsoft 365 for Mac: setting read through AppleScript, drop per Microsoft's documentation)
Question before replacing none "There's already data here. Do you want to replace it?" OK / Cancel "There's already data here. Do you want to replace it?" OK / Cancel (Alert before overwriting cells = true by default, read through AppleScript)
A1:A3 after the drop Kiwi, Plum, Lime (Apple, Pear, Fig lost) unchanged until answered; unchanged on Cancel (Apple, Pear, Fig) unchanged on Cancel; Kiwi, Plum, Lime on OK
A1:A3 after OK — Kiwi, Plum, Lime; column B empty Kiwi, Plum, Lime; column B empty

Tests

  • cmd::edit::tests::drag_and_drop_asks_before_replacing_data (engine): the question, nothing moved and the earlier copy kept on refusal, overwrite: true replaces, no question onto empty cells or onto the moved cells' own place, to required.
  • drag_cursor::moving_a_selection_onto_data_asks_before_replacing_it (ui-egui, real pointer input): the drop asks, nothing changes until Enter (OK), then the cells move.
  • Both fail on main without the fix and pass with it. cargo xtask ci passes.

Anything a reviewer should look at first

  • Excel's drop itself: I could read the setting through AppleScript but could not complete a pointer drag in Excel on this machine, so the question text and the OK/Cancel outcome follow Microsoft's public "Move or copy cells, rows, and columns" documentation and the Alert before overwriting cells option rather than an observed drop.
  • What counts as "data": cells with a value, formula or Python code (Cell::has_content); formatting alone doesn't ask. Cells inside the moved range itself never ask.
  • Not in this PR (the reporter's "swap" wish): Shift+drag to insert the moved cells (Excel's way to reorder) and Ctrl/Option+drag to copy are still not wired to the border drag. Whole columns can already be reordered by dragging their selected headers (sheet.moveColumns).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added drag-and-drop movement for selected cell ranges. Dropping onto populated cells asks for confirmation before replacing data; confirming performs the move, while canceling leaves the data unchanged. Drops onto empty cells or overlapping parts of the selection do not require confirmation.
  • Documentation
    • Updated the grid interaction notes to describe range movement and its replacement confirmation. Ctrl/Option-copy and Shift-insert remain unsupported.

Dragging the selection's border onto cells that hold data replaced them
without asking, so dragging column B onto column A silently destroyed A.
Excel asks "There's already data here. Do you want to replace it?" first
(its "Alert before overwriting cells" option, on by default).

The drop now runs a new `range.move {range?, to, overwrite?}` command:
a cut and paste that returns a confirm question when the destination
holds data other than the moved cells; the grid shows it with OK and
Cancel, and OK runs it again with `overwrite: true`. A refused move
leaves the sheet and the clipboard as they were.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 16 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 8 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 6874e0b and ba1c624.

Files selected for processing: 2
  • crates/engine/src/cmd/edit/clipboard.rs
  • crates/engine/src/cmd/edit/tests.rs
Walkthrough

The change adds the range.move command with replacement confirmation and clipboard restoration on errors. Grid border-drag moves now use this command. Tests cover confirmation and replacement behavior, and the parity documentation records the behavior and unsupported modifiers.

Changes: Range Move

Layer / File(s) Summary
Register and implement range.move
crates/engine/src/cmd/edit.rs, crates/engine/src/cmd/edit/clipboard.rs, crates/engine/src/cmd/edit/tests.rs
The command accepts an optional source range, a required destination, and an optional overwrite flag. It asks for confirmation before replacing cells with content or non-empty spilled values outside the source range. Tests cover confirmation, overwriting, empty destinations, overlapping moves, a missing destination, and sheet-qualified sources.
Use range.move for grid border drags
crates/ui-egui/src/grid/interact.rs, crates/ui-egui/tests/it/drag_cursor.rs, docs/ui-parity.md
The grid calls range.move when a dragged range is released at a different starting cell. The integration test checks the replacement question and resulting cell values. The parity documentation records the behavior and notes that Ctrl/Option-copy and Shift-insert remain unsupported.

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

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Grid
  participant RangeMove as range.move
  participant Sheet
  User->>Grid: Release dragged range at a different starting cell
  Grid->>RangeMove: Call with source range and destination
  RangeMove->>Sheet: Check destination for content outside the source
  RangeMove-->>Grid: Return confirmation error if replacement needs confirmation
  Grid-->>User: Show replacement question
  User->>Grid: Confirm replacement
  RangeMove->>Sheet: Paste moved range at destination
Loading

Suggested reviewers: aiongg, prxnvt

Merge Risk: Low · previous review 6874e

A move on another sheet can leave the visible sheet’s selection at an unrelated location. This is a bounded issue suitable for follow-up.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Linked Issues check Warning Issue #3136 reports that moving column B before column A must not destroy column A and describes swapping the columns as the expected result. The PR adds confirmation before destructive replacement, b… Implement the #3136 column move behavior so moving column B to column A repositions or swaps the columns without losing column A. Add an automated test for the reported scenario. Preserve confirmation for other destructive border drops if t…
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title states the main change: a drag-and-drop move now asks for confirmation before it replaces existing data. The raw summary, objectives, and linked issue #3136 all describe this confirmation be…
Out of Scope Changes check Passed The new range.move command, confirmation UI path, regression tests, and ui-parity documentation directly support the linked drag-and-drop data-loss issue. The sheet-qualified move and spilled-value ch…
Full details: Title check

Explanation

The title states the main change: a drag-and-drop move now asks for confirmation before it replaces existing data. The raw summary, objectives, and linked issue #3136 all describe this confirmation behavior, so the title matches the changeset. It does not mention the new range.move command, but that detail is not required in a title.

Full details: Out of Scope Changes check

Explanation

The new range.move command, confirmation UI path, regression tests, and ui-parity documentation directly support the linked drag-and-drop data-loss issue. The sheet-qualified move and spilled-value checks support the same behavior. No unrelated change is established.

Full details: Linked Issues check

Explanation

Issue #3136 reports that moving column B before column A must not destroy column A and describes swapping the columns as the expected result. The PR adds confirmation before destructive replacement, but the confirmed move still replaces destination data. The PR does not implement column repositioning or swapping for the reported scenario. The added tests verify confirmation and replacement, not the issue’s expected column result.

Resolution

Implement the #3136 column move behavior so moving column B to column A repositions or swaps the columns without losing column A. Add an automated test for the reported scenario. Preserve confirmation for other destructive border drops if that behavior remains supported.

Full details: Docstring Coverage

Explanation

Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 5 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 5361e2c and 6874e0b.

Files selected for processing: 2
  • crates/engine/src/cmd/edit/clipboard.rs
  • crates/engine/src/cmd/edit/tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • Fix comments: Fix CodeRabbit comments on this PR

Comment thread crates/engine/src/cmd/edit/clipboard.rs Resolved
Comment thread crates/engine/src/cmd/edit/clipboard.rs Resolved
…e replacing spilled values

Addresses CodeRabbit review on storytold#3216:
- "Pass the resolved sheet to the paste step": a sheet-qualified move
  (`Two!B1:B2` with Sheet1 active) was checked on Two but pasted on the
  active sheet, replacing its data unasked. range.move now calls
  paste_special with the range's sheet.
- "Check spilled values in the drop destination": cells showing a dynamic
  array's spilled values hold no cell of their own, so the drop replaced
  them without the prompt. They now count as data, as in Excel
  (ISBLANK of a spill cell is FALSE, COUNTA counts it).

Tests: drag_and_drop_on_another_sheet_stays_on_that_sheet,
drag_and_drop_asks_before_replacing_spilled_values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hectorviov

Copy link
Copy Markdown
Contributor Author

About the Linked Issues pre-merge warning (the issue asks for column B to swap places with column A): a plain border drag in Excel doesn't swap. It asks "There's already data here. Do you want to replace it?" and replaces on OK, which is what this PR adds. The swap the reporter wants is Excel's Shift+drag (insert between columns). The PR description already lists that as a follow-up, so I'm keeping this PR to the data-loss part. I'm leaving the docstring coverage warning as is, because range_move already has a doc comment.

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • Fix comments: Fix CodeRabbit comments on this PR

Comment thread crates/engine/src/cmd/edit/clipboard.rs Resolved
…ction

Addresses CodeRabbit review on storytold#3216, "Keep the selection on the sheet it
describes": moving Two!B1:B2 with Sheet1 active selected A1:A2 on
Sheet1, where nothing moved. The selection belongs to the active sheet,
so range.move now keeps it when the moved cells are on another sheet; a
move on the active sheet still selects the moved cells.

Test: drag_and_drop_on_another_sheet_stays_on_that_sheet (now also
checks the selection).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit affae49 into storytold:main Nov 3, 2026
1 check passed
@echelon

echelon commented Nov 3, 2026

Copy link
Copy Markdown
Member

Merged — thank you @hectorviov for the contribution!

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.

[Bug Report] [GridCraft] Column Repositioning Bug

3 participants