diff --git a/input.cpp b/input.cpp index a90d84a54..7855ee52a 100644 --- a/input.cpp +++ b/input.cpp @@ -130,7 +130,8 @@ static const wchar_t *name_arr[] = L"repaint", L"up-line", L"down-line", - L"suppress-autosuggestion" + L"suppress-autosuggestion", + L"accept-autosuggestion" } ; @@ -213,6 +214,7 @@ static const wchar_t code_arr[] = R_UP_LINE, R_DOWN_LINE, R_SUPPRESS_AUTOSUGGESTION, + R_ACCEPT_AUTOSUGGESTION } ; @@ -257,7 +259,6 @@ void input_mapping_add( const wchar_t *sequence, const wchar_t *command ) { size_t i; - CHECK( sequence, ); CHECK( command, ); @@ -445,7 +446,7 @@ static wint_t input_try_mapping( const input_mapping_t &m) { wint_t c=0; int j; - + /* Check if the actual function code of this mapping is on the stack */ diff --git a/input.h b/input.h index e62fe2bb6..28c09d497 100644 --- a/input.h +++ b/input.h @@ -50,6 +50,7 @@ enum R_UP_LINE, R_DOWN_LINE, R_SUPPRESS_AUTOSUGGESTION, + R_ACCEPT_AUTOSUGGESTION } ; diff --git a/reader.cpp b/reader.cpp index 5c295539b..32bf33b29 100644 --- a/reader.cpp +++ b/reader.cpp @@ -1204,6 +1204,18 @@ static void update_autosuggestion(void) { #endif } +static void accept_autosuggestion(void) { + /* Accept any autosuggestion by replacing the command line with it. */ + if (! data->autosuggestion.empty()) { + /* Accept the autosuggestion */ + data->command_line = data->autosuggestion; + data->buff_pos = data->command_line.size(); + data->command_line_changed(); + reader_super_highlight_me_plenty(data->buff_pos); + reader_repaint(); + } +} + /** Flash the screen. This function only changed the color of the current line, since the flash_screen sequnce is rather painful to @@ -3015,15 +3027,7 @@ const wchar_t *reader_readline() data->buff_pos++; reader_repaint(); } else { - /* We're at the end of our buffer, and the user hit right. Try autosuggestion. */ - if (! data->autosuggestion.empty()) { - /* Accept the autosuggestion */ - data->command_line = data->autosuggestion; - data->buff_pos = data->command_line.size(); - data->command_line_changed(); - reader_super_highlight_me_plenty(data->buff_pos); - reader_repaint(); - } + accept_autosuggestion(); } break; } @@ -3113,7 +3117,7 @@ const wchar_t *reader_readline() break; } - + case R_SUPPRESS_AUTOSUGGESTION: { data->suppress_autosuggestion = true; @@ -3121,6 +3125,12 @@ const wchar_t *reader_readline() reader_repaint(); break; } + + case R_ACCEPT_AUTOSUGGESTION: + { + accept_autosuggestion(); + break; + } /* Other, if a normal character, we add it to the command */ default: