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 }, { 'd', do_erase },
{ 'c', do_change }, { 'c', do_change },
{ 'i', [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::Insert); } }, { '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::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::OpenLineBelow); } },
{ 'O', [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::OpenLineAbove); } }, { '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::Change: pos = sel.begin(); break;
case Mode::OpenLineBelow: case Mode::OpenLineBelow:
pos = sel.last(); case Mode::AppendAtLineEnd:
pos = sel.end() - 1;
while (not pos.is_end() and *pos != '\n') while (not pos.is_end() and *pos != '\n')
++pos; ++pos;
++pos; if (mode == Mode::OpenLineBelow)
window.m_buffer.insert(pos, "\n"); {
++pos;
window.m_buffer.insert(pos, "\n");
}
break; break;
case Mode::OpenLineAbove: case Mode::OpenLineAbove:
case Mode::InsertAtLineBegin:
pos = sel.begin(); pos = sel.begin();
while (not pos.is_begin() and *pos != '\n') while (not pos.is_begin() and *pos != '\n')
--pos; --pos;
window.m_buffer.insert(pos, "\n"); if (mode == Mode::OpenLineAbove)
window.m_buffer.insert(pos, "\n");
++pos; ++pos;
break; break;
} }

View File

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