From cee0a2d128bb843cd4a65dcddb66188ea825553e Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 26 Nov 2012 19:23:50 +0100 Subject: [PATCH] Append on end of line now appends to current line --- src/editor.cc | 11 ++++++++++- src/editor.hh | 1 + src/main.cc | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/editor.cc b/src/editor.cc index eeffe41f..7ad9b610 100644 --- a/src/editor.cc +++ b/src/editor.cc @@ -38,10 +38,19 @@ static BufferIterator prepare_insert(Buffer& buffer, const Selection& sel, case InsertMode::Replace: return sel.begin(); case InsertMode::Append: - return sel.end(); + { + // special case for end of lines, append to current line instead + auto pos = std::max(sel.first(), sel.last()); + if (pos.column() == buffer.line_length(pos.line()) - 1) + return pos; + else + return pos+1; + } case InsertMode::InsertAtLineBegin: return buffer.iterator_at_line_begin(sel.begin()); case InsertMode::AppendAtLineEnd: + return buffer.iterator_at_line_end(sel.end()-1)-1; + case InsertMode::InsertAtNextLineBegin: return buffer.iterator_at_line_end(sel.end()-1); case InsertMode::OpenLineBelow: { diff --git a/src/editor.hh b/src/editor.hh index 10239564..06b9378a 100644 --- a/src/editor.hh +++ b/src/editor.hh @@ -26,6 +26,7 @@ enum class InsertMode : unsigned Append, Replace, InsertAtLineBegin, + InsertAtNextLineBegin, AppendAtLineEnd, OpenLineBelow, OpenLineAbove diff --git a/src/main.cc b/src/main.cc index 9f252c5b..d05245b0 100644 --- a/src/main.cc +++ b/src/main.cc @@ -169,7 +169,7 @@ void do_change(Context& context) static InsertMode adapt_for_linewise(InsertMode mode) { if (mode == InsertMode::Append) - return InsertMode::AppendAtLineEnd; + return InsertMode::InsertAtNextLineBegin; if (mode == InsertMode::Insert) return InsertMode::InsertAtLineBegin; if (mode == InsertMode::Replace)