mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-12 09:20:36 +00:00
PixelPaint: Fix first undo action not working
This commit is contained in:
parent
c7431da3f2
commit
80e70f95ab
Notes:
sideshowbarker
2024-07-18 03:01:49 +09:00
Author: https://github.com/mrkct Commit: https://github.com/SerenityOS/serenity/commit/80e70f95abc Pull-request: https://github.com/SerenityOS/serenity/pull/10208 Issue: https://github.com/SerenityOS/serenity/issues/5814
1 changed files with 24 additions and 12 deletions
|
@ -50,22 +50,34 @@ void ImageEditor::did_complete_action()
|
|||
|
||||
bool ImageEditor::undo()
|
||||
{
|
||||
if (m_undo_stack->can_undo()) {
|
||||
m_undo_stack->undo();
|
||||
layers_did_change();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (!m_undo_stack->can_undo())
|
||||
return false;
|
||||
|
||||
/* 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
|
||||
* 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()
|
||||
{
|
||||
if (m_undo_stack->can_redo()) {
|
||||
m_undo_stack->redo();
|
||||
layers_did_change();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (!m_undo_stack->can_redo())
|
||||
return false;
|
||||
|
||||
m_undo_stack->redo();
|
||||
layers_did_change();
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImageEditor::paint_event(GUI::PaintEvent& event)
|
||||
|
|
Loading…
Reference in a new issue