Replicate same changes from c0dfb832d8 for redo (#3539)

This commit is contained in:
David Capello 2022-09-29 11:04:05 -03:00
parent c0dfb832d8
commit 5c4024c44f
1 changed files with 13 additions and 9 deletions

View File

@ -101,9 +101,9 @@ bool DocUndo::canRedo() const
void DocUndo::undo()
{
const size_t oldSize = m_totalUndoSize;
const undo::UndoState* state = nextUndo();
ASSERT(state);
{
const undo::UndoState* state = nextUndo();
ASSERT(state);
const Cmd* cmd = STATE_CMD(state);
m_totalUndoSize -= cmd->memSize();
m_undoHistory.undo();
@ -120,16 +120,16 @@ void DocUndo::undo()
void DocUndo::redo()
{
const undo::UndoState* state = nextRedo();
ASSERT(state);
const Cmd* cmd = STATE_CMD(state);
size_t oldSize = m_totalUndoSize;
m_totalUndoSize -= cmd->memSize();
const size_t oldSize = m_totalUndoSize;
{
const undo::UndoState* state = nextRedo();
ASSERT(state);
const Cmd* cmd = STATE_CMD(state);
m_totalUndoSize -= cmd->memSize();
m_undoHistory.redo();
notify_observers(&DocUndoObserver::onCurrentUndoStateChange, this);
m_totalUndoSize += cmd->memSize();
}
m_totalUndoSize += cmd->memSize();
notify_observers(&DocUndoObserver::onCurrentUndoStateChange, this);
if (m_totalUndoSize != oldSize)
notify_observers(&DocUndoObserver::onTotalUndoSizeChange, this);
}
@ -226,6 +226,10 @@ Cmd* DocUndo::lastExecutedCmd() const
void DocUndo::moveToState(const undo::UndoState* state)
{
m_undoHistory.moveTo(state);
// After onCurrentUndoStateChange don't use the "state" argument, it
// might be deleted because some script might have modified the
// sprite on its "change" event.
notify_observers(&DocUndoObserver::onCurrentUndoStateChange, this);
// Recalculate the total undo size