summaryrefslogtreecommitdiff
path: root/src/buffer.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2012-11-21 13:43:10 +0100
committerMaxime Coste <frrrwww@gmail.com>2012-11-21 13:43:10 +0100
commitd1fade5c9e7ec622ce1c1ed5d6c4418753068e09 (patch)
tree0f45217cf79ba4051219dfa740ecfc339fc32748 /src/buffer.cc
parentac6171686d1ec71dd4452bdf0045d8afd97556ec (diff)
Buffer: replace reset_undo_data with a NoUndo flag
Diffstat (limited to 'src/buffer.cc')
-rw-r--r--src/buffer.cc30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/buffer.cc b/src/buffer.cc
index 3e6eb6e7..a540772a 100644
--- a/src/buffer.cc
+++ b/src/buffer.cc
@@ -14,7 +14,7 @@ namespace Kakoune
Buffer::Buffer(String name, Flags flags,
String initial_content)
- : m_name(std::move(name)), m_flags(flags),
+ : m_name(std::move(name)), m_flags(flags | Flags::NoUndo),
m_history(), m_history_cursor(m_history.begin()),
m_last_save_undo_index(0),
m_timestamp(0),
@@ -26,7 +26,6 @@ Buffer::Buffer(String name, Flags flags,
initial_content += '\n';
do_insert(begin(), std::move(initial_content));
-
Editor editor_for_hooks(*this);
Context context(editor_for_hooks);
if (flags & Flags::File and flags & Flags::New)
@@ -36,7 +35,8 @@ Buffer::Buffer(String name, Flags flags,
m_hook_manager.run_hook("BufCreate", m_name, context);
- reset_undo_data();
+ // now we may begin to record undo data
+ m_flags = flags;
}
Buffer::~Buffer()
@@ -148,6 +148,9 @@ String Buffer::string(const BufferIterator& begin, const BufferIterator& end) co
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());
@@ -159,6 +162,9 @@ void Buffer::begin_undo_group()
void Buffer::end_undo_group()
{
+ if (m_flags & Flags::NoUndo)
+ return;
+
if (m_current_undo_group.empty())
return;
@@ -217,13 +223,6 @@ bool Buffer::redo()
return true;
}
-void Buffer::reset_undo_data()
-{
- m_history.clear();
- m_history_cursor = m_history.end();
- m_current_undo_group.clear();
-}
-
void Buffer::check_invariant() const
{
ByteCount start = 0;
@@ -370,9 +369,9 @@ void Buffer::insert(BufferIterator pos, String content)
if (pos.is_end() and content.back() != '\n')
content += '\n';
- m_current_undo_group.emplace_back(Modification::Insert, pos,
- std::move(content));
- do_insert(pos, m_current_undo_group.back().content);
+ if (not (m_flags & Flags::NoUndo))
+ m_current_undo_group.emplace_back(Modification::Insert, pos, content);
+ do_insert(pos, content);
}
void Buffer::erase(BufferIterator begin, BufferIterator end)
@@ -383,8 +382,9 @@ void Buffer::erase(BufferIterator begin, BufferIterator end)
if (begin == end)
return;
- m_current_undo_group.emplace_back(Modification::Erase, begin,
- string(begin, end));
+ if (not (m_flags & Flags::NoUndo))
+ m_current_undo_group.emplace_back(Modification::Erase, begin,
+ string(begin, end));
do_erase(begin, end);
}