IncrementalInserter: support insert at line begin and append at line end

This commit is contained in:
Maxime Coste 2011-11-02 20:03:41 +00:00
parent 856a870d8b
commit 4982620c4c
3 changed files with 14 additions and 4 deletions

View File

@ -512,7 +512,9 @@ std::unordered_map<char, std::function<void (Window& window, int count)>> keymap
{ 'd', do_erase },
{ 'c', do_change },
{ 'i', [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::Insert); } },
{ 'I', [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::InsertAtLineBegin); } },
{ 'a', [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::Append); } },
{ 'A', [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::AppendAtLineEnd); } },
{ 'o', [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::OpenLineBelow); } },
{ 'O', [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::OpenLineAbove); } },

View File

@ -399,18 +399,24 @@ IncrementalInserter::IncrementalInserter(Window& window, Mode mode)
case Mode::Change: pos = sel.begin(); break;
case Mode::OpenLineBelow:
pos = sel.last();
case Mode::AppendAtLineEnd:
pos = sel.end() - 1;
while (not pos.is_end() and *pos != '\n')
++pos;
++pos;
window.m_buffer.insert(pos, "\n");
if (mode == Mode::OpenLineBelow)
{
++pos;
window.m_buffer.insert(pos, "\n");
}
break;
case Mode::OpenLineAbove:
case Mode::InsertAtLineBegin:
pos = sel.begin();
while (not pos.is_begin() and *pos != '\n')
--pos;
window.m_buffer.insert(pos, "\n");
if (mode == Mode::OpenLineAbove)
window.m_buffer.insert(pos, "\n");
++pos;
break;
}

View File

@ -105,6 +105,8 @@ public:
Insert,
Append,
Change,
InsertAtLineBegin,
AppendAtLineEnd,
OpenLineBelow,
OpenLineAbove
};