IncrementalInserter: support OpenLineBelow and OpenLineAbove mode
This commit is contained in:
parent
cf9f8c93ec
commit
571e4772b4
|
@ -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 },
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,7 +124,9 @@ public:
|
|||
{
|
||||
Insert,
|
||||
Append,
|
||||
Change
|
||||
Change,
|
||||
OpenLineBelow,
|
||||
OpenLineAbove
|
||||
};
|
||||
|
||||
IncrementalInserter(Window& window, Mode mode = Mode::Insert);
|
||||
|
|
Loading…
Reference in New Issue
Block a user