diff --git a/src/reader.cpp b/src/reader.cpp index 3e99975a6..963b2379a 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -4404,6 +4404,13 @@ bool reader_data_t::handle_execute(readline_loop_state_t &rls) { // using a backslash, insert a newline. // If the user hits return while navigating the pager, it only clears the pager. if (is_navigating_pager_contents()) { + if (this->history_pager_active && + this->pager.selected_completion_index() == PAGER_SELECTION_NONE) { + command_line.push_edit( + edit_t{0, command_line.size(), this->pager.search_field_line.text()}, + /* allow_coalesce */ false); + command_line.set_position(this->pager.search_field_line.position()); + } clear_pager(); return true; } diff --git a/tests/checks/tmux-history-search.fish b/tests/checks/tmux-history-search.fish index 92bab0b80..7b2425400 100644 --- a/tests/checks/tmux-history-search.fish +++ b/tests/checks/tmux-history-search.fish @@ -27,3 +27,10 @@ isolated-tmux send-keys C-z _ tmux-sleep isolated-tmux capture-pane -p | grep 'prompt 2' # CHECK: prompt 2> _ + +# When history pager fails to find a result, copy the search field to the command line. +isolated-tmux send-keys C-e C-u C-r "echo no such command in history" +tmux-sleep +isolated-tmux send-keys Enter +# CHECK: prompt 2> echo no such command in history +isolated-tmux capture-pane -p | grep 'prompt 2'