mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:27:44 +00:00
PixelPaint: Fix first undo action not working
This commit is contained in:
parent
c7431da3f2
commit
80e70f95ab
1 changed files with 24 additions and 12 deletions
|
@ -50,22 +50,34 @@ void ImageEditor::did_complete_action()
|
||||||
|
|
||||||
bool ImageEditor::undo()
|
bool ImageEditor::undo()
|
||||||
{
|
{
|
||||||
if (m_undo_stack->can_undo()) {
|
if (!m_undo_stack->can_undo())
|
||||||
m_undo_stack->undo();
|
return false;
|
||||||
layers_did_change();
|
|
||||||
return true;
|
/* Without this you need to undo twice to actually start undoing stuff.
|
||||||
}
|
* This is due to the fact that the top of the UndoStack contains the snapshot of the currently
|
||||||
return false;
|
* shown image but what we actually want to restore is the snapshot right below it.
|
||||||
|
* Doing "undo->undo->redo" restores the 2nd topmost snapshot on the stack while lowering the
|
||||||
|
* stack pointer only by 1. This is important because we want the UndoStack's pointer to always point
|
||||||
|
* at the currently shown snapshot, otherwise doing 'undo->undo->draw something else' would delete
|
||||||
|
* one of the snapshots.
|
||||||
|
* This works because UndoStack::undo first decrements the stack pointer and then restores the snapshot,
|
||||||
|
* while UndoStack::redo first restores the snapshot and then increments the stack pointer.
|
||||||
|
*/
|
||||||
|
m_undo_stack->undo();
|
||||||
|
m_undo_stack->undo();
|
||||||
|
m_undo_stack->redo();
|
||||||
|
layers_did_change();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImageEditor::redo()
|
bool ImageEditor::redo()
|
||||||
{
|
{
|
||||||
if (m_undo_stack->can_redo()) {
|
if (!m_undo_stack->can_redo())
|
||||||
m_undo_stack->redo();
|
return false;
|
||||||
layers_did_change();
|
|
||||||
return true;
|
m_undo_stack->redo();
|
||||||
}
|
layers_did_change();
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageEditor::paint_event(GUI::PaintEvent& event)
|
void ImageEditor::paint_event(GUI::PaintEvent& event)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue