Fix issue where transpose fails if there is a trailing autosuggestion

This commit is contained in:
ridiculousfish 2013-05-24 23:53:10 -07:00
parent f32dfe2da6
commit ee95a7309a

View file

@ -3043,7 +3043,7 @@ const wchar_t *reader_readline(void)
else else
{ {
/* Either the user hit tab only once, or we had no visible completion list. */ /* Either the user hit tab only once, or we had no visible completion list. */
/* Remove a trailing backslash. This may trigger an extra repaint, but this is rare. */ /* Remove a trailing backslash. This may trigger an extra repaint, but this is rare. */
if (is_backslashed(data->command_line, data->buff_pos)) if (is_backslashed(data->command_line, data->buff_pos))
{ {
@ -3544,7 +3544,8 @@ const wchar_t *reader_readline(void)
case R_TRANSPOSE_CHARS: case R_TRANSPOSE_CHARS:
{ {
if (data->command_length() < 2) { if (data->command_length() < 2)
{
break; break;
} }
@ -3560,11 +3561,9 @@ const wchar_t *reader_readline(void)
*/ */
if (data->buff_pos > 0) if (data->buff_pos > 0)
{ {
wchar_t tmp = data->command_line[data->buff_pos]; wcstring local_cmd = data->command_line;
data->command_line[data->buff_pos] = data->command_line[data->buff_pos-1]; std::swap(local_cmd.at(data->buff_pos), local_cmd.at(data->buff_pos-1));
data->command_line[data->buff_pos-1] = tmp; set_command_line_and_position(local_cmd, data->buff_pos + 1);
data->buff_pos++;
reader_repaint();
} }
break; break;
} }