IncrementalInserter: refactoring

This commit is contained in:
Maxime Coste 2011-11-29 21:35:50 +00:00
parent b24dec89a2
commit e89516f2a3

View File

@ -393,7 +393,7 @@ IncrementalInserter::IncrementalInserter(Window& window, Mode mode)
for (auto& sel : m_window.m_selections) for (auto& sel : m_window.m_selections)
{ {
BufferIterator pos; DynamicBufferIterator pos;
switch (mode) switch (mode)
{ {
case Mode::Insert: pos = sel.begin(); break; case Mode::Insert: pos = sel.begin(); break;
@ -402,24 +402,16 @@ IncrementalInserter::IncrementalInserter(Window& window, Mode mode)
case Mode::OpenLineBelow: case Mode::OpenLineBelow:
case Mode::AppendAtLineEnd: case Mode::AppendAtLineEnd:
pos = sel.end() - 1; pos = m_window.m_buffer.iterator_at_line_end(sel.end() - 1) - 1;
while (not pos.is_end() and *pos != '\n')
++pos;
if (mode == Mode::OpenLineBelow) if (mode == Mode::OpenLineBelow)
{
++pos;
window.m_buffer.insert(pos, "\n"); window.m_buffer.insert(pos, "\n");
}
break; break;
case Mode::OpenLineAbove: case Mode::OpenLineAbove:
case Mode::InsertAtLineBegin: case Mode::InsertAtLineBegin:
pos = sel.begin(); pos = m_window.m_buffer.iterator_at_line_begin(sel.begin());
while (not pos.is_begin() and *pos != '\n')
--pos;
if (mode == Mode::OpenLineAbove) if (mode == Mode::OpenLineAbove)
window.m_buffer.insert(pos, "\n"); window.m_buffer.insert(--pos, "\n");
++pos;
break; break;
} }
sel = Selection(pos, pos, sel.captures()); sel = Selection(pos, pos, sel.captures());