add Buffer::{undo,redo}()
This commit is contained in:
parent
e0615011a3
commit
2057c69585
@ -386,3 +386,34 @@ void Buffer::apply_change_unit(const ChangeUnit & change_unit, bool forward)
|
||||
erase_data(change_unit.buffer_position, change_unit.length);
|
||||
}
|
||||
}
|
||||
|
||||
void Buffer::undo()
|
||||
{
|
||||
if (m_current_change_operation_index != INVALID_CHANGE_OPERATION_INDEX)
|
||||
{
|
||||
apply_change_operation(*m_change_operations[m_current_change_operation_index], false);
|
||||
m_current_change_operation_index = m_change_operations[m_current_change_operation_index]->parent;
|
||||
}
|
||||
}
|
||||
|
||||
void Buffer::redo()
|
||||
{
|
||||
size_t child_index = INVALID_CHANGE_OPERATION_INDEX;
|
||||
if (m_current_change_operation_index == INVALID_CHANGE_OPERATION_INDEX)
|
||||
{
|
||||
if (m_change_operations.size() > 0u)
|
||||
{
|
||||
child_index = 0u;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
child_index = *m_change_operations[m_current_change_operation_index]->children.begin();
|
||||
}
|
||||
|
||||
if (child_index != INVALID_CHANGE_OPERATION_INDEX)
|
||||
{
|
||||
apply_change_operation(*m_change_operations[child_index], true);
|
||||
m_current_change_operation_index = child_index;
|
||||
}
|
||||
}
|
||||
|
@ -134,6 +134,8 @@ public:
|
||||
Iterator end() const { return *m_eof_iterator; }
|
||||
void push_operation() { m_operation_level++; }
|
||||
void pop_operation();
|
||||
void undo();
|
||||
void redo();
|
||||
|
||||
protected:
|
||||
bool m_eol_at_eof;
|
||||
|
Loading…
x
Reference in New Issue
Block a user