From 63d4c8c3114862a49a2a4a54b2f229f9260bf291 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 4 Jul 2018 19:42:32 +1000 Subject: [PATCH] Change `a` on end of line behaviour to be consistent `a` will just jump on next line, `a` on last end of line opens a new line beneath it. Fixes #1164 --- doc/pages/changelog.asciidoc | 4 ++++ rc/core/c-family.kak | 2 +- src/input_handler.cc | 12 +++++------- src/selection.cc | 6 +----- test/normal/repeat-insert/cmd | 2 +- test/normal/replay-macro/rc | 2 +- .../1680-crash-with-dot-and-alt-semicolon/out | 1 + 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/doc/pages/changelog.asciidoc b/doc/pages/changelog.asciidoc index 8c9e7c9c..1fa43f29 100644 --- a/doc/pages/changelog.asciidoc +++ b/doc/pages/changelog.asciidoc @@ -53,6 +53,10 @@ change to make Kakoune command model cleaner and more robust. See <> +* `a` on end of line is not treated specially anymore, it will start + inserting on the next character, which will be the first character + of the next line. + == Kakoune 2018.04.13 First official Kakoune release. diff --git a/rc/core/c-family.kak b/rc/core/c-family.kak index 162e94c2..9c89ae0e 100644 --- a/rc/core/c-family.kak +++ b/rc/core/c-family.kak @@ -74,7 +74,7 @@ define-command -hidden c-family-indent-on-closing-curly-brace %[ define-command -hidden c-family-insert-on-closing-curly-brace %[ # add a semicolon after a closing brace if part of a class, union or struct definition - try %[ execute-keys -itersel -draft hmB\A\h*(class|struct|union|enum) a\; ] + try %[ execute-keys -itersel -draft hmB\A\h*(class|struct|union|enum) ';i;' ] ] define-command -hidden c-family-insert-on-newline %[ evaluate-commands -itersel -draft %[ diff --git a/src/input_handler.cc b/src/input_handler.cc index 51453e08..cf9773c9 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -1117,7 +1117,7 @@ public: { for (auto& sel : selections) { - if (sel.cursor() > sel.anchor() and sel.cursor().column > 0) + if (sel.cursor() > sel.anchor() and sel.cursor() > BufferCoord{0, 0}) sel.cursor() = context().buffer().char_prev(sel.cursor()); } } @@ -1362,11 +1362,9 @@ private: case InsertMode::Append: for (auto& sel : selections) { - sel.set(sel.min(), sel.max()); - auto& cursor = sel.cursor(); - // special case for end of lines, append to current line instead - if (cursor.column != buffer[cursor.line].length() - 1) - cursor = buffer.char_next(cursor); + sel.set(sel.min(), buffer.char_next(sel.max())); + if (sel.cursor() == buffer.end_coord()) + buffer.insert(buffer.end_coord(), "\n"); } break; case InsertMode::AppendAtLineEnd: @@ -1434,7 +1432,7 @@ private: ScopedEdition m_edition; InsertCompleter m_completer; - bool m_restore_cursor; + const bool m_restore_cursor; bool m_autoshowcompl; Timer m_idle_timer; bool m_in_end = false; diff --git a/src/selection.cc b/src/selection.cc index c8ab543b..c245095d 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -357,11 +357,7 @@ BufferCoord get_insert_pos(const Buffer& buffer, const Selection& sel, case InsertMode::InsertCursor: return sel.cursor(); case InsertMode::Append: - { - // special case for end of lines, append to current line instead - auto pos = sel.max(); - return buffer.byte_at(pos) == '\n' ? pos : buffer.char_next(pos); - } + return buffer.char_next(sel.max()); case InsertMode::InsertAtLineBegin: return sel.min().line; case InsertMode::AppendAtLineEnd: diff --git a/test/normal/repeat-insert/cmd b/test/normal/repeat-insert/cmd index 8eb06025..607416f6 100644 --- a/test/normal/repeat-insert/cmd +++ b/test/normal/repeat-insert/cmd @@ -1 +1 @@ -afoo. +ifoo. diff --git a/test/normal/replay-macro/rc b/test/normal/replay-macro/rc index 00d2afcb..59da97d8 100644 --- a/test/normal/replay-macro/rc +++ b/test/normal/replay-macro/rc @@ -1 +1 @@ -reg @ amawww +reg @ imawww diff --git a/test/regression/1680-crash-with-dot-and-alt-semicolon/out b/test/regression/1680-crash-with-dot-and-alt-semicolon/out index 55b5f1fc..7b6c900f 100644 --- a/test/regression/1680-crash-with-dot-and-alt-semicolon/out +++ b/test/regression/1680-crash-with-dot-and-alt-semicolon/out @@ -1 +1,2 @@ + foofoo