Skip to content

fix: restore individual cell values on undo for multi-cell paste#1199

Merged
ghiscoding merged 1 commit into
masterfrom
bugfix/external-copy-undo
May 6, 2026
Merged

fix: restore individual cell values on undo for multi-cell paste#1199
ghiscoding merged 1 commit into
masterfrom
bugfix/external-copy-undo

Conversation

@ghiscoding

@ghiscoding ghiscoding commented May 5, 2026

Copy link
Copy Markdown
Collaborator

fixes #917

vibe coded a fix with Copilot

Description

Fixes issue #917 where undoing a multi-cell paste operation in CellExternalCopyManager incorrectly restores all cells to the same value instead of their individual previous values.

Root Cause

When pasting a single cell value to multiple cells (oneCellToMultiple), the undo function was incorrectly retrieving the old value. It used oldValues[0][0] for all cells instead of oldValues[y][x - xOffset], causing all cells to be restored to the first cell's previous value.

Reproduction Steps

  1. Open example-excel-compatible-spreadsheet.html
  2. Copy a single cell value
  3. Select a range of multiple cells
  4. Paste the single value (applies to all selected cells as expected)
  5. Press Ctrl+Z to undo
  6. Bug: All cells are incorrectly restored to the same value

Solution

  • Removed the oneCellToMultiple condition from the undo function
  • Added proper xOffset tracking to handle hidden columns correctly (consistent with the execute function)
  • Each cell now restores from its own stored old value: oldValues[y][x - xOffset]

Testing

  1. Copy a single cell with value "A"
  2. Select a range of 4 cells (e.g., containing "B", "C", "D", "E")
  3. Paste (all 4 cells now contain "A")
  4. Undo (all 4 cells should be restored to their original values "B", "C", "D", "E")
  5. Verify each cell is restored correctly

Impact

  • Fixes undo behavior for multi-cell paste operations
  • No breaking changes
  • Properly handles hidden columns in the restore process

@ghiscoding

Copy link
Copy Markdown
Collaborator Author

validated the fix in Slickgrid-Universal in the UI and it works and the fix is valid

@ghiscoding ghiscoding merged commit 9aa520c into master May 6, 2026
5 of 6 checks passed
@ghiscoding ghiscoding deleted the bugfix/external-copy-undo branch May 6, 2026 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problem with undo in CellExternalCopyManager

1 participant