Skip to content

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

Open
ghiscoding wants to merge 3 commits intomasterfrom
bugfix/external-copy-undo
Open

fix: restore individual cell values on undo for multi-cell paste#2570
ghiscoding wants to merge 3 commits intomasterfrom
bugfix/external-copy-undo

Conversation

@ghiscoding
Copy link
Copy Markdown
Owner

@ghiscoding ghiscoding commented May 6, 2026

fixes an old issue opened in SlickGrid (6pac) project: 6pac/SlickGrid#917

vibe coded a fix with Copilot

Description

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

The Problem Explained

The oneCellToMultiple paste feature allows users to copy a single cell and paste it to multiple cells at once (like Excel). However, when undoing this operation, the bug causes all pasted cells to be restored to the same previous value instead of each cell being restored to its own individual previous value.

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.

Additionally, the undo function was not properly tracking xOffset for hidden columns, unlike the execute function which handles this correctly.

Detailed Reproduction Steps

  1. Setup Initial Grid Values:

    • Cell A1 = "Apple"
    • Cell B1 = "Book", B2 = "Car", B3 = "Dog", B4 = "Egg"
  2. Copy Single Cell:

    • Click on cell A1 (contains "Apple")
    • Press Ctrl+C to copy
  3. Paste to Multiple Cells:

    • Select the range B1:B4 (all 4 cells)
    • Press Ctrl+V to paste
    • Expected Result: All cells now show "Apple" ✓
    • Cells now contain: B1="Apple", B2="Apple", B3="Apple", B4="Apple"
  4. Undo the Paste:

    • Press Ctrl+Z to undo
    • Expected Result (FIXED): Each cell should restore to its original value
      • B1 should be "Book", B2 should be "Car", B3 should be "Dog", B4 should be "Egg"
    • Previous Buggy Behavior: All cells would incorrectly become "Book" (the first cell's previous value)

Solution

  • Removed the flawed oneCellToMultiple conditional 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]

Impact

  • ✓ Fixes undo behavior for multi-cell paste operations
  • ✓ No breaking changes
  • ✓ Properly handles hidden columns in the restore process
  • ✓ Makes undo behavior consistent with user expectations (each cell returns to its previous value)

@ghiscoding
Copy link
Copy Markdown
Owner Author

ghiscoding commented May 6, 2026

@zewa666 would you mind providing your point of view to this PR, I literally looked at all the old opened SlickGrid issues and vibe coded fixes for a few of them (using copilot for free). Then looked at reimplementing it in here in Slickgrid-Universal at work with copilot again (it also confirmed that we also have that problem here too).

It's supposed to fix issue mentioned in 6pac/SlickGrid#917 and I asked copilot to provide all the steps to reproduce.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.0%. Comparing base (1518e49) to head (4a54be3).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2570   +/-   ##
=======================================
  Coverage   100.0%   100.0%           
=======================================
  Files         196      196           
  Lines       24982    24984    +2     
  Branches     8826     8825    -1     
=======================================
+ Hits        24982    24984    +2     
Flag Coverage Δ
angular 100.0% <ø> (ø)
universal 100.0% <100.0%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ghiscoding ghiscoding requested a review from zewa666 May 6, 2026 21:16
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 6, 2026

angular-slickgrid

npm i https://pkg.pr.new/angular-slickgrid@2570

aurelia-slickgrid

npm i https://pkg.pr.new/aurelia-slickgrid@2570

slickgrid-react

npm i https://pkg.pr.new/slickgrid-react@2570

slickgrid-vue

npm i https://pkg.pr.new/slickgrid-vue@2570

@slickgrid-universal/angular-row-detail-plugin

npm i https://pkg.pr.new/@slickgrid-universal/angular-row-detail-plugin@2570

@slickgrid-universal/aurelia-row-detail-plugin

npm i https://pkg.pr.new/@slickgrid-universal/aurelia-row-detail-plugin@2570

@slickgrid-universal/react-row-detail-plugin

npm i https://pkg.pr.new/@slickgrid-universal/react-row-detail-plugin@2570

@slickgrid-universal/vue-row-detail-plugin

npm i https://pkg.pr.new/@slickgrid-universal/vue-row-detail-plugin@2570

@slickgrid-universal/binding

npm i https://pkg.pr.new/@slickgrid-universal/binding@2570

@slickgrid-universal/common

npm i https://pkg.pr.new/@slickgrid-universal/common@2570

@slickgrid-universal/composite-editor-component

npm i https://pkg.pr.new/@slickgrid-universal/composite-editor-component@2570

@slickgrid-universal/custom-footer-component

npm i https://pkg.pr.new/@slickgrid-universal/custom-footer-component@2570

@slickgrid-universal/custom-tooltip-plugin

npm i https://pkg.pr.new/@slickgrid-universal/custom-tooltip-plugin@2570

@slickgrid-universal/empty-warning-component

npm i https://pkg.pr.new/@slickgrid-universal/empty-warning-component@2570

@slickgrid-universal/event-pub-sub

npm i https://pkg.pr.new/@slickgrid-universal/event-pub-sub@2570

@slickgrid-universal/excel-export

npm i https://pkg.pr.new/@slickgrid-universal/excel-export@2570

@slickgrid-universal/graphql

npm i https://pkg.pr.new/@slickgrid-universal/graphql@2570

@slickgrid-universal/odata

npm i https://pkg.pr.new/@slickgrid-universal/odata@2570

@slickgrid-universal/pagination-component

npm i https://pkg.pr.new/@slickgrid-universal/pagination-component@2570

@slickgrid-universal/pdf-export

npm i https://pkg.pr.new/@slickgrid-universal/pdf-export@2570

@slickgrid-universal/row-detail-view-plugin

npm i https://pkg.pr.new/@slickgrid-universal/row-detail-view-plugin@2570

@slickgrid-universal/rxjs-observable

npm i https://pkg.pr.new/@slickgrid-universal/rxjs-observable@2570

@slickgrid-universal/sql

npm i https://pkg.pr.new/@slickgrid-universal/sql@2570

@slickgrid-universal/text-export

npm i https://pkg.pr.new/@slickgrid-universal/text-export@2570

@slickgrid-universal/utils

npm i https://pkg.pr.new/@slickgrid-universal/utils@2570

@slickgrid-universal/vanilla-bundle

npm i https://pkg.pr.new/@slickgrid-universal/vanilla-bundle@2570

@slickgrid-universal/vanilla-force-bundle

npm i https://pkg.pr.new/@slickgrid-universal/vanilla-force-bundle@2570

commit: 4a54be3

@ghiscoding
Copy link
Copy Markdown
Owner Author

ghiscoding commented May 6, 2026

I actually had to add the "Undo" and Edit Queue functionality in the Example 19 to test it out, and it does seem to work as the fix suggest. Basically in 1 "Undo", it should revert all cell range to their original values

msedge_Aop5EzZu2I

@zewa666
Copy link
Copy Markdown
Collaborator

zewa666 commented May 6, 2026

oh thats a very good catch. will check it out tomorrow

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.

2 participants