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
This commit is contained in:
Maxime Coste 2018-09-04 07:55:56 +10:00
parent b581a4fbed
commit 37e2558413
2 changed files with 57 additions and 4 deletions

View File

@ -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 <<registers#,`:doc registers`>>).
When pressing `:` in normal mode, Kakoune will open a prompt to enter
a command. The executed command line is stored in the *:* register
(See <<registers#,`:doc registers`>>).
The following keys are recognized by this mode to help with editing (See <<commands#,`:doc commands`>>).
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 <<commands#,`:doc commands`>>).
*<ret>*::
validate prompt
@ -715,6 +720,27 @@ The following keys are recognized by this mode to help with editing (See <<comma
*<a-E>*::
advance to next word end
*<c-w>*::
erase to previous word begin, save erased content to *clipboard*
*<c-W>*::
erase to previous WORD begin, save erased content to *clipboard*
*<a-d>*::
erase to previous word end, save erased content to *clipboard*
*<a-D>*::
erase to previous WORD end, save erased content to *clipboard*
*<c-k>*::
erase to end of line, save erased content to *clipboard*
*<c-u>*::
erase to begin of line, save erased content to *clipboard*
*<c-y>*::
insert *clipboard* content before cursor
*<up>*, *<c-p>*::
select previous entry in history

View File

@ -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;
};