1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 10:18:13 +00:00

Spreadsheet: Make undo operation handle multiple cells at a time

Instead of having the undo operation only be able to undo one cell
for a given undo, make it able to handle multiple cells at a time.
 Please enter the commit message for your changes. Lines starting
This commit is contained in:
martinfalisse 2022-04-07 23:04:36 +02:00 committed by Ali Mohammad Pur
parent 7bd0ebb1ab
commit 22575c9370
7 changed files with 59 additions and 31 deletions

View file

@ -165,4 +165,29 @@ void SheetModel::update()
m_sheet->update();
did_update(UpdateFlag::DontInvalidateIndices);
}
CellsUndoCommand::CellsUndoCommand(Vector<CellChange> cell_changes)
{
m_cell_changes = cell_changes;
}
CellsUndoCommand::CellsUndoCommand(Cell& cell, String const& previous_data)
{
m_cell_changes.append(CellChange(cell, previous_data));
}
void CellsUndoCommand::undo()
{
for (size_t i = 0; i < m_cell_changes.size(); ++i) {
m_cell_changes[i].cell().set_data(m_cell_changes[i].previous_data());
}
}
void CellsUndoCommand::redo()
{
for (size_t i = 0; i < m_cell_changes.size(); ++i) {
m_cell_changes[i].cell().set_data(m_cell_changes[i].new_data());
}
}
}