Added binding for accepting an autosuggestion

Fixes https://github.com/fish-shell/fish-shell/issues/226
This commit is contained in:
ridiculousfish 2012-07-15 14:02:34 -07:00
parent 4755c5f8c8
commit 548ea1e54a
3 changed files with 25 additions and 13 deletions

View file

@ -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
*/

View file

@ -50,6 +50,7 @@ enum
R_UP_LINE,
R_DOWN_LINE,
R_SUPPRESS_AUTOSUGGESTION,
R_ACCEPT_AUTOSUGGESTION
}
;

View file

@ -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: