mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 09:49:15 +03:00
74a4571f02
The undo stack was very difficult to understand as it grew by adding new undo commands to the front of the internal vector. This meant we had to keep updating indices as the stack grew and shrank. This patch makes the internal vector grow by appending instead.
47 lines
750 B
C++
47 lines
750 B
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/NonnullOwnPtrVector.h>
|
|
#include <LibGUI/Forward.h>
|
|
|
|
namespace GUI {
|
|
|
|
class UndoStack {
|
|
public:
|
|
UndoStack();
|
|
~UndoStack();
|
|
|
|
void push(NonnullOwnPtr<Command>&&);
|
|
|
|
bool can_undo() const;
|
|
bool can_redo() const;
|
|
|
|
void undo();
|
|
void redo();
|
|
|
|
void finalize_current_combo();
|
|
|
|
void set_current_unmodified();
|
|
bool is_current_modified() const;
|
|
|
|
void clear();
|
|
|
|
private:
|
|
struct Combo {
|
|
NonnullOwnPtrVector<Command> commands;
|
|
};
|
|
|
|
void pop();
|
|
|
|
NonnullOwnPtrVector<Combo> m_stack;
|
|
size_t m_stack_index { 0 };
|
|
Optional<size_t> m_clean_index;
|
|
};
|
|
|
|
}
|