diff options
| author | Maxime Coste <mawww@kakoune.org> | 2018-09-04 07:55:56 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2018-09-04 07:55:56 +1000 |
| commit | 37e25584139de0dd5a27b0f079c1243943692a18 (patch) | |
| tree | 0c73f114aeb8a891152a85e2c7739580d9a188f7 /src/input_handler.cc | |
| parent | b581a4fbedd0912a53bb6f238ea99d4f8d175ec0 (diff) | |
Add readline word erase bindings, throw in clipboard for good measure
Add <c-w> and <a-d> (along with <c-W> and <a-D> that work on WORDs),
and <c-y> which pastes the transient clipboard contant (which saves
big erase, such as word erase and line end/begin erase).
Fixes #2355
Diffstat (limited to 'src/input_handler.cc')
| -rw-r--r-- | src/input_handler.cc | 29 |
1 files changed, 28 insertions, 1 deletions
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<WORD>(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<Word>); + else if (key == ctrl('W')) + erase_move(&to_prev_word_begin<Word>); + else if (key == alt('d')) + erase_move(&to_next_word_begin<Word>); + else if (key == alt('D')) + erase_move(&to_next_word_begin<WORD>); + 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; }; |
