From ee572a13c8e542b847a540227d12a682d6fe2ad7 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Thu, 25 May 2017 20:46:38 -0700 Subject: [PATCH] fix regression introduced by 21521b2 The problem was overlooking a `break` statement when refactoring a `switch` block into a simpler `if...else...` block. This fixes the behavior of the `history-token-search-backward` function and its forward searching analog. Fixes #4065 (cherry picked from commit 8f78e71b6d71bd26fabbe4ab88aa44fba1f68351) --- src/builtin.cpp | 1 - src/reader.cpp | 22 +++++++--------------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/builtin.cpp b/src/builtin.cpp index b407511ce..a17903444 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -560,7 +560,6 @@ static int builtin_bind(parser_t &parser, io_streams_t &streams, wchar_t **argv) argv[0], eseq.c_str()); } } - break; } else { if (builtin_bind_add(argv[w.woptind], argv + (w.woptind + 1), argc - (w.woptind + 1), bind_mode, sets_bind_mode, diff --git a/src/reader.cpp b/src/reader.cpp index 1a84a135a..96d6d2950 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -1781,22 +1781,14 @@ static void handle_token_history(int forward, int reset) { tokenizer_t tok(data->token_history_buff.c_str(), TOK_ACCEPT_UNFINISHED); tok_t token; while (tok.next(&token)) { - if (token.type == TOK_STRING) { - if (token.text.find(data->search_buff) != wcstring::npos) { - // debug( 3, L"Found token at pos %d\n", tok_get_pos( &tok ) ); - if (token.offset >= current_pos) { - break; - } - // debug( 3, L"ok pos" ); + if (token.type != TOK_STRING) continue; + if (token.text.find(data->search_buff) == wcstring::npos) continue; + if (token.offset >= current_pos) continue; - if (find(data->search_prev.begin(), data->search_prev.end(), token.text) == - data->search_prev.end()) { - data->token_history_pos = token.offset; - str = token.text; - } - } - } else { - break; + auto found = find(data->search_prev.begin(), data->search_prev.end(), token.text); + if (found == data->search_prev.end()) { + data->token_history_pos = token.offset; + str = token.text; } } }