summaryrefslogtreecommitdiff
path: root/src/buffer.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-01-23 14:27:21 +0100
committerMaxime Coste <frrrwww@gmail.com>2013-01-23 14:39:33 +0100
commit72cc61c987d29eb4fc41db1c3e2f2c92f9b3ebac (patch)
tree005812194ef4aba43602c144f19b6c32890984d5 /src/buffer.cc
parent3404366b6593bbf372da35ef8c7ce6cde429cef7 (diff)
add undo unit_test and fix Buffer
Diffstat (limited to 'src/buffer.cc')
-rw-r--r--src/buffer.cc10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/buffer.cc b/src/buffer.cc
index d384f3bb..266d4905 100644
--- a/src/buffer.cc
+++ b/src/buffer.cc
@@ -272,7 +272,7 @@ void Buffer::do_insert(const BufferIterator& pos, const String& content)
if (start != content.length())
m_lines.push_back({ offset + start, content.substr(start) });
- begin_it = pos;
+ begin_it = BufferIterator{*this, { pos.line() + 1, 0 }};
end_it = end();
}
else
@@ -349,8 +349,14 @@ void Buffer::do_erase(const BufferIterator& begin, const BufferIterator& end)
void Buffer::apply_modification(const Modification& modification)
{
const String& content = modification.content;
- const BufferIterator& pos = modification.position;
+ BufferIterator pos = modification.position;
+
+ // this may happen when a modification applied at the
+ // end of the buffer has been inverted for an undo.
+ if (pos.column() == m_lines[pos.line()].length())
+ pos = { pos.buffer(), { pos.line() + 1, 0 }};
+ assert(pos.is_valid());
switch (modification.type)
{
case Modification::Insert: