diff --git a/src/main.cc b/src/main.cc index 31c2a3e2..288fcf10 100644 --- a/src/main.cc +++ b/src/main.cc @@ -504,6 +504,8 @@ std::unordered_map> 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 }, diff --git a/src/window.cc b/src/window.cc index 21666dd2..dc3cc1a7 100644 --- a/src/window.cc +++ b/src/window.cc @@ -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); } } diff --git a/src/window.hh b/src/window.hh index 8b8eb3fe..dd7f593b 100644 --- a/src/window.hh +++ b/src/window.hh @@ -124,7 +124,9 @@ public: { Insert, Append, - Change + Change, + OpenLineBelow, + OpenLineAbove }; IncrementalInserter(Window& window, Mode mode = Mode::Insert);