Mark cells and add to undo?

Tags: #<Tag:0x00007efc6abf3cf0> #<Tag:0x00007efc6abf3890>

Is there a way to get marking of cells added to the undo/redo stack?

Like if the user colors a cell, they would expect to be able to undo that using ctrl+z, but I cannot find a way to get that working

Hi @rene.sinnbeck

metadata changes are not stacked in the undoRedo - we stack only operations on data. We can see it here https://jsfiddle.net/handsoncode/4kqx76up/ that the afterSetCellMeta hook is triggered when we change values via RMB-menu but undo stack does not change.

As a workaround you’d need to block the CTRL/CMD + Z shortcut if cell meta change was done after user changed value of a cell, so I guess that you’d need to keep those cell meta changes in it’s own stack. To remove the metadata change you can call the removeCellMeta() method.

For one change that seems easy, but with multiple changes and/or users that might be too complex. As an alternative you can think about adding an additional shortcut for undoing only metadata changes. Then you can use the ShortcutManager to add a new shortcut. Using metadata undo stack seems easier to manage.

1 Like

@aleksandra_budnik

Yeah that was my fear. I had hoped that there was some trick I just didnt find :slight_smile:
I dont suppose there it would work if I set the data to be an array of objects and have a color: key in there, that I change?

Generally, setting up anything other than a primitive to a cell is a challenge - you’d need to set up some additional custom functions. Here’s an example of a fully working key-value dropdown (with cell renderer, validator, and editor) https://jsfiddle.net/handsoncode/f0b41jug/. In the line 39 there’s a logic to set the data - even though the cell contains an object the data is still a single string.