Copy history pager search field to command line on Enter if no match

Closes #9934

(cherry picked from commit b7f7dcf788)
This commit is contained in:
Johannes Altmanninger 2023-08-08 21:53:42 +02:00 committed by Fabian Boehm
parent 64bff1a51c
commit 211a3ceee1
2 changed files with 14 additions and 0 deletions

View File

@ -4389,6 +4389,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;
}

View File

@ -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'