Module: wine Branch: master Commit: 105db4c5381c1ab6e5a2542b6aa7d7a2f1bdaf81 URL: https://source.winehq.org/git/wine.git/?a=commit;h=105db4c5381c1ab6e5a2542b6...
Author: Jacek Caban jacek@codeweavers.com Date: Mon Jan 4 21:13:50 2021 +0100
conhost: Fix wrapping search in edit_line_find_in_history.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50000 Signed-off-by: Jacek Caban jacek@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
programs/conhost/conhost.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-)
diff --git a/programs/conhost/conhost.c b/programs/conhost/conhost.c index 3e41577a44b..0ac1c5f507b 100644 --- a/programs/conhost/conhost.c +++ b/programs/conhost/conhost.c @@ -691,6 +691,7 @@ static void edit_line_find_in_history( struct console *console ) unsigned int len, oldoffset; WCHAR *line;
+ if (!console->history_index) return; if (ctx->history_index && ctx->history_index == console->history_index) { start_pos--; @@ -699,28 +700,28 @@ static void edit_line_find_in_history( struct console *console )
do { - line = edit_line_history(console, ctx->history_index); - - if (ctx->history_index) ctx->history_index--; - else ctx->history_index = console->history_index; - - len = lstrlenW(line) + 1; - if (len >= ctx->cursor && !memcmp( ctx->buf, line, ctx->cursor * sizeof(WCHAR) )) - { - /* need to clean also the screen if new string is shorter than old one */ - edit_line_delete(console, 0, ctx->len); - - if (edit_line_grow(console, len)) - { - oldoffset = ctx->cursor; - ctx->cursor = 0; - edit_line_insert( console, line, len - 1 ); - ctx->cursor = oldoffset; - free(line); - return; - } - } - free(line); + line = edit_line_history(console, ctx->history_index); + + if (ctx->history_index) ctx->history_index--; + else ctx->history_index = console->history_index - 1; + + len = lstrlenW(line) + 1; + if (len >= ctx->cursor && !memcmp( ctx->buf, line, ctx->cursor * sizeof(WCHAR) )) + { + /* need to clean also the screen if new string is shorter than old one */ + edit_line_delete(console, 0, ctx->len); + + if (edit_line_grow(console, len)) + { + oldoffset = ctx->cursor; + ctx->cursor = 0; + edit_line_insert( console, line, len - 1 ); + ctx->cursor = oldoffset; + free(line); + return; + } + } + free(line); } while (ctx->history_index != start_pos); }