mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-24 20:13:00 +03:00
IncrementalInserter: support insert at line begin and append at line end
This commit is contained in:
parent
856a870d8b
commit
4982620c4c
@ -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); } },
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -105,6 +105,8 @@ public:
|
||||
Insert,
|
||||
Append,
|
||||
Change,
|
||||
InsertAtLineBegin,
|
||||
AppendAtLineEnd,
|
||||
OpenLineBelow,
|
||||
OpenLineAbove
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user