Buffer: replace {begin,end}_undo_group with a single commit_undo_group method

This commit is contained in:
Maxime Coste 2013-02-20 14:20:16 +01:00
parent 682e4faff0
commit 9f4498e035
4 changed files with 11 additions and 30 deletions

View File

@ -152,21 +152,7 @@ String Buffer::string(const BufferIterator& begin, const BufferIterator& end) co
return res;
}
void Buffer::begin_undo_group()
{
if (m_flags & Flags::NoUndo)
return;
assert(m_current_undo_group.empty());
m_history.erase(m_history_cursor, m_history.end());
if (m_history.size() < m_last_save_undo_index)
m_last_save_undo_index = -1;
m_history_cursor = m_history.end();
}
void Buffer::end_undo_group()
void Buffer::commit_undo_group()
{
if (m_flags & Flags::NoUndo)
return;
@ -174,10 +160,14 @@ void Buffer::end_undo_group()
if (m_current_undo_group.empty())
return;
m_history.erase(m_history_cursor, m_history.end());
m_history.push_back(std::move(m_current_undo_group));
m_current_undo_group.clear();
m_history_cursor = m_history.end();
m_current_undo_group.clear();
if (m_history.size() < m_last_save_undo_index)
m_last_save_undo_index = -1;
}
// A Modification holds a single atomic modification to Buffer
@ -414,10 +404,7 @@ bool Buffer::is_modified() const
void Buffer::notify_saved()
{
if (not m_current_undo_group.empty())
{
end_undo_group();
begin_undo_group();
}
commit_undo_group();
m_flags &= ~Flags::New;
size_t history_cursor_index = m_history_cursor - m_history.begin();

View File

@ -115,8 +115,7 @@ public:
size_t timestamp() const { return m_timestamp; }
void begin_undo_group();
void end_undo_group();
void commit_undo_group();
bool undo();
bool redo();

View File

@ -384,16 +384,13 @@ void Editor::check_invariant() const
void Editor::begin_edition()
{
++m_edition_level;
if (m_edition_level == 1)
m_buffer->begin_undo_group();
}
void Editor::end_edition()
{
assert(m_edition_level > 0);
if (m_edition_level == 1)
m_buffer->end_undo_group();
m_buffer->commit_undo_group();
--m_edition_level;
}

View File

@ -40,12 +40,10 @@ void test_buffer()
buffer.insert(buffer.end(), "kanaky\n");
assert(buffer.string(begin+1, buffer.end()) == "kanaky\n");
buffer.end_undo_group();
buffer.begin_undo_group();
buffer.commit_undo_group();
buffer.erase(begin+1, buffer.end());
buffer.insert(buffer.end(), "mutch\n");
buffer.end_undo_group();
buffer.commit_undo_group();
buffer.undo();
assert(buffer.string(buffer.end() - 7, buffer.end()) == "kanaky\n");
buffer.redo();