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"repaint",
L"up-line", L"up-line",
L"down-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_UP_LINE,
R_DOWN_LINE, R_DOWN_LINE,
R_SUPPRESS_AUTOSUGGESTION, R_SUPPRESS_AUTOSUGGESTION,
R_ACCEPT_AUTOSUGGESTION
} }
; ;
@ -257,7 +259,6 @@ void input_mapping_add( const wchar_t *sequence,
const wchar_t *command ) const wchar_t *command )
{ {
size_t i; size_t i;
CHECK( sequence, ); CHECK( sequence, );
CHECK( command, ); CHECK( command, );

View file

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

View file

@ -1204,6 +1204,18 @@ static void update_autosuggestion(void) {
#endif #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 Flash the screen. This function only changed the color of the
current line, since the flash_screen sequnce is rather painful to current line, since the flash_screen sequnce is rather painful to
@ -3015,15 +3027,7 @@ const wchar_t *reader_readline()
data->buff_pos++; data->buff_pos++;
reader_repaint(); reader_repaint();
} else { } else {
/* We're at the end of our buffer, and the user hit right. Try autosuggestion. */ accept_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();
}
} }
break; break;
} }
@ -3122,6 +3126,12 @@ const wchar_t *reader_readline()
break; break;
} }
case R_ACCEPT_AUTOSUGGESTION:
{
accept_autosuggestion();
break;
}
/* Other, if a normal character, we add it to the command */ /* Other, if a normal character, we add it to the command */
default: default:
{ {