IncrementalInserter: support OpenLineBelow and OpenLineAbove mode

This commit is contained in:
Maxime Coste 2011-10-06 21:12:55 +00:00
parent cf9f8c93ec
commit 571e4772b4
3 changed files with 28 additions and 2 deletions

View File

@ -504,6 +504,8 @@ std::unordered_map<char, std::function<void (Window& window, int count)>> keymap
{ 'c', do_change },
{ 'i', [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::Insert); } },
{ 'a', [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::Append); } },
{ 'o', [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::OpenLineBelow); } },
{ 'O', [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::OpenLineAbove); } },
{ 'g', do_go },

View File

@ -371,7 +371,29 @@ IncrementalInserter::IncrementalInserter(Window& window, Mode mode)
for (auto& sel : m_window.m_selections)
{
const BufferIterator& pos = mode == Mode::Append ? sel.end() : sel.begin();
BufferIterator pos;
switch (mode)
{
case Mode::Insert: pos = sel.begin(); break;
case Mode::Append: pos = sel.end(); break;
case Mode::Change: pos = sel.begin(); break;
case Mode::OpenLineBelow:
pos = sel.end();
while (not pos.is_end() and *pos != '\n')
++pos;
++pos;
window.m_buffer.insert(pos, "\n");
break;
case Mode::OpenLineAbove:
pos = sel.begin();
while (not pos.is_begin() and *pos != '\n')
--pos;
window.m_buffer.insert(pos, "\n");
++pos;
break;
}
sel = Selection(pos, pos);
}
}

View File

@ -124,7 +124,9 @@ public:
{
Insert,
Append,
Change
Change,
OpenLineBelow,
OpenLineAbove
};
IncrementalInserter(Window& window, Mode mode = Mode::Insert);