From 4982620c4c67a83276dd2b126002178b34f57c5c Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 2 Nov 2011 20:03:41 +0000 Subject: [PATCH] IncrementalInserter: support insert at line begin and append at line end --- src/main.cc | 2 ++ src/window.cc | 14 ++++++++++---- src/window.hh | 2 ++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main.cc b/src/main.cc index 19689c83..55aeb0d2 100644 --- a/src/main.cc +++ b/src/main.cc @@ -512,7 +512,9 @@ std::unordered_map> 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); } }, diff --git a/src/window.cc b/src/window.cc index 942be83a..59f18892 100644 --- a/src/window.cc +++ b/src/window.cc @@ -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; } diff --git a/src/window.hh b/src/window.hh index 843bdb4f..6442a3fd 100644 --- a/src/window.hh +++ b/src/window.hh @@ -105,6 +105,8 @@ public: Insert, Append, Change, + InsertAtLineBegin, + AppendAtLineEnd, OpenLineBelow, OpenLineAbove };