From ee95a7309a5e89031188642c8c2e4c77283d6433 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Fri, 24 May 2013 23:53:10 -0700 Subject: [PATCH] Fix issue where transpose fails if there is a trailing autosuggestion --- reader.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/reader.cpp b/reader.cpp index 2a26b050d..c51414668 100644 --- a/reader.cpp +++ b/reader.cpp @@ -3043,7 +3043,7 @@ const wchar_t *reader_readline(void) else { /* 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. */ if (is_backslashed(data->command_line, data->buff_pos)) { @@ -3544,7 +3544,8 @@ const wchar_t *reader_readline(void) case R_TRANSPOSE_CHARS: { - if (data->command_length() < 2) { + if (data->command_length() < 2) + { break; } @@ -3560,11 +3561,9 @@ const wchar_t *reader_readline(void) */ if (data->buff_pos > 0) { - wchar_t tmp = data->command_line[data->buff_pos]; - data->command_line[data->buff_pos] = data->command_line[data->buff_pos-1]; - data->command_line[data->buff_pos-1] = tmp; - data->buff_pos++; - reader_repaint(); + wcstring local_cmd = data->command_line; + std::swap(local_cmd.at(data->buff_pos), local_cmd.at(data->buff_pos-1)); + set_command_line_and_position(local_cmd, data->buff_pos + 1); } break; }