From ac60522373291a96a7fe7261eb9e61928a8ae09e Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 29 Aug 2020 10:59:20 +0200 Subject: [PATCH] Stop history searches with no results to allow up-or-search to move the cursor Enter a multiline commandline, for example using commandline -i echo echo And press down-arrow. This will start a new history search which fails. Then press up-arrow. I expect the cursor to move up, however, because we are still in history search mode, up-or-search will search instead of moving the cursor. Correct that by stopping history searches that don't have any results. --- src/reader.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/reader.cpp b/src/reader.cpp index da4e3587f..7d045ed5f 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -3053,6 +3053,8 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat ? reader_history_search_t::prefix : reader_history_search_t::line; + bool was_active_before = history_search.active(); + if (history_search.is_at_end()) { const editable_line_t *el = &command_line; if (mode == reader_history_search_t::token) { @@ -3086,7 +3088,12 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat c == rl::history_prefix_search_backward) ? history_search_direction_t::backward : history_search_direction_t::forward; - if (history_search.move_in_direction(dir) || + bool found = history_search.move_in_direction(dir); + if (!found && !was_active_before) { + history_search.reset(); + break; + } + if (found || (dir == history_search_direction_t::forward && history_search.is_at_end())) { update_command_line_from_history_search(); }