From 37e25584139de0dd5a27b0f079c1243943692a18 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 4 Sep 2018 07:55:56 +1000 Subject: [PATCH] Add readline word erase bindings, throw in clipboard for good measure Add and (along with and that work on WORDs), and which pastes the transient clipboard contant (which saves big erase, such as word erase and line end/begin erase). Fixes #2355 --- doc/pages/keys.asciidoc | 32 +++++++++++++++++++++++++++++--- src/input_handler.cc | 29 ++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/doc/pages/keys.asciidoc b/doc/pages/keys.asciidoc index 7f66d3d5..78de0049 100644 --- a/doc/pages/keys.asciidoc +++ b/doc/pages/keys.asciidoc @@ -668,10 +668,15 @@ in order to specify the wanted object: == Prompt commands -When pressing `:` in normal mode, Kakoune will open a prompt to enter a command. -The executed command line is stored in the *:* register (See <>). +When pressing `:` in normal mode, Kakoune will open a prompt to enter +a command. The executed command line is stored in the *:* register +(See <>). -The following keys are recognized by this mode to help with editing (See <>). +During edition, a transient *clipboard* is available, its content is +empty at the start of prompt edition, and is not preserved afterwards. + +The following keys are recognized by this mode to help with editing +(See <>). **:: validate prompt @@ -715,6 +720,27 @@ The following keys are recognized by this mode to help with editing (See <*:: advance to next word end +**:: + erase to previous word begin, save erased content to *clipboard* + +**:: + erase to previous WORD begin, save erased content to *clipboard* + +**:: + erase to previous word end, save erased content to *clipboard* + +**:: + erase to previous WORD end, save erased content to *clipboard* + +**:: + erase to end of line, save erased content to *clipboard* + +**:: + erase to begin of line, save erased content to *clipboard* + +**:: + insert *clipboard* content before cursor + **, **:: select previous entry in history diff --git a/src/input_handler.cc b/src/input_handler.cc index df63933c..b423f713 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -437,6 +437,15 @@ public: void handle_key(Key key) { + auto erase_move = [this](auto&& move_func) { + auto old_pos = m_cursor_pos; + move_func(m_cursor_pos, m_line); + if (m_cursor_pos > old_pos) + std::swap(m_cursor_pos, old_pos); + m_clipboard = m_line.substr(m_cursor_pos, old_pos - m_cursor_pos).str(); + m_line = m_line.substr(0, m_cursor_pos) + m_line.substr(old_pos); + }; + if (key == Key::Left or key == ctrl('b')) { if (m_cursor_pos > 0) @@ -480,12 +489,29 @@ public: else if (key == alt('E')) to_next_word_end(m_cursor_pos, m_line); else if (key == ctrl('k')) - m_line = m_line.substr(0_char, m_cursor_pos).str(); + { + m_clipboard = m_line.substr(m_cursor_pos).str(); + m_line = m_line.substr(0, m_cursor_pos).str(); + } else if (key == ctrl('u')) { + m_clipboard = m_line.substr(0, m_cursor_pos).str(); m_line = m_line.substr(m_cursor_pos).str(); m_cursor_pos = 0; } + else if (key == ctrl('w') or key == alt(Key::Backspace)) + erase_move(&to_prev_word_begin); + else if (key == ctrl('W')) + erase_move(&to_prev_word_begin); + else if (key == alt('d')) + erase_move(&to_next_word_begin); + else if (key == alt('D')) + erase_move(&to_next_word_begin); + else if (key == ctrl('y')) + { + m_line = m_line.substr(0, m_cursor_pos) + m_clipboard + m_line.substr(m_cursor_pos); + m_cursor_pos += m_clipboard.char_length(); + } else if (auto cp = key.codepoint()) insert(*cp); } @@ -555,6 +581,7 @@ private: String m_line; StringView m_empty_text = {}; + String m_clipboard; const FaceRegistry& m_faces; };