From 67a0c046059565663df74e6a026ddd27f5950863 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Wed, 6 Sep 2023 21:42:54 +0200 Subject: [PATCH] reader: Use existing search string when opening the history pager I sometimes find myself doing something like this: - Look for a commandline that includes "echo" (as an example) - Type echo, press up a few times - I can't immediately find what I'm looking for - Press ctrl-r to open up the history pager - It uses the current commandline as the search string, so now I'm looking for "echo foobar" This makes it so if the search string already is in use, that's what the history-pager picks as the initial search string. (cherry picked from commit 5b44c26a197fd73a4aa465fa1d43bb4c67805fd0) --- src/reader.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/reader.cpp b/src/reader.cpp index 8669ac111..d3bfa17fb 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -3757,7 +3757,13 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat pager.set_search_field_shown(true); pager.set_prefix(MB_CUR_MAX > 1 ? L"► " : L"> ", false /* highlight */); // Update the search field, which triggers the actual history search. - insert_string(&pager.search_field_line, command_line.text()); + if (!history_search.active() || history_search.search_string().empty()) { + insert_string(&pager.search_field_line, command_line.text()); + } else { + // If we have an actual history search already going, reuse that term + // - this is if the user looks around a bit and decides to switch to the pager. + insert_string(&pager.search_field_line, history_search.search_string()); + } break; } case rl::backward_char: {