Buffer::Modification::Position is a BufferCoord instead of a BufferIterator

This commit is contained in:
Maxime Coste 2013-04-26 18:45:24 +02:00
parent f8c3b6c9ef
commit b16c967f9c

View File

@ -200,12 +200,12 @@ struct Buffer::Modification
{ {
enum Type { Insert, Erase }; enum Type { Insert, Erase };
Type type; Type type;
BufferIterator position; BufferCoord coord;
String content; String content;
Modification(Type type, BufferIterator position, String content) Modification(Type type, BufferCoord coord, String content)
: type(type), position(position), content(std::move(content)) {} : type(type), coord(coord), content(std::move(content)) {}
Modification inverse() const Modification inverse() const
{ {
@ -216,7 +216,7 @@ struct Buffer::Modification
case Erase: inverse_type = Insert; break; case Erase: inverse_type = Insert; break;
default: kak_assert(false); default: kak_assert(false);
} }
return {inverse_type, position, content}; return {inverse_type, coord, content};
} }
}; };
@ -370,14 +370,14 @@ void Buffer::do_erase(const BufferIterator& begin, const BufferIterator& end)
void Buffer::apply_modification(const Modification& modification) void Buffer::apply_modification(const Modification& modification)
{ {
const String& content = modification.content; const String& content = modification.content;
BufferIterator pos = modification.position; BufferCoord coord = modification.coord;
// this may happen when a modification applied at the // this may happen when a modification applied at the
// end of the buffer has been inverted for an undo. // end of the buffer has been inverted for an undo.
if (not pos.is_end() and pos.column() == m_lines[pos.line()].length()) if (coord.line < line_count()-1 and coord.column == m_lines[coord.line].length())
pos = { pos.buffer(), { pos.line() + 1, 0 }}; coord = { coord.line + 1, 0 };
kak_assert(pos.is_valid()); BufferIterator pos{*this, coord};
switch (modification.type) switch (modification.type)
{ {
case Modification::Insert: case Modification::Insert:
@ -407,7 +407,7 @@ void Buffer::insert(BufferIterator pos, String content)
content += '\n'; content += '\n';
if (not (m_flags & Flags::NoUndo)) if (not (m_flags & Flags::NoUndo))
m_current_undo_group.emplace_back(Modification::Insert, pos, content); m_current_undo_group.emplace_back(Modification::Insert, pos.coord(), content);
do_insert(pos, content); do_insert(pos, content);
} }
@ -420,7 +420,7 @@ void Buffer::erase(BufferIterator begin, BufferIterator end)
return; return;
if (not (m_flags & Flags::NoUndo)) if (not (m_flags & Flags::NoUndo))
m_current_undo_group.emplace_back(Modification::Erase, begin, m_current_undo_group.emplace_back(Modification::Erase, begin.coord(),
string(begin, end)); string(begin, end));
do_erase(begin, end); do_erase(begin, end);
} }