diff --git a/src/reader.rs b/src/reader.rs index 7e6a65752..455cd7728 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -1894,30 +1894,28 @@ fn replace_current_token(&mut self, new_token: WString) { /// Apply the history search to the command line. fn update_command_line_from_history_search(&mut self) { - let new_text = if self.history_search.is_at_present() { - self.history_search.search_string() - } else { - self.history_search.current_result() - } - .to_owned(); + assert!(self.history_search.active()); if self.command_line_has_transient_edit { self.undo(EditableLineTag::Commandline); + self.command_line_has_transient_edit = false; } - if self.history_search.by_token() { - self.replace_current_token(new_text); - } else { - assert!(self.history_search.by_line() || self.history_search.by_prefix()); - self.replace_substring( - EditableLineTag::Commandline, - 0..self.command_line.len(), - new_text, - ); - if self.history_search.by_prefix() { - self.command_line - .set_position(self.history_search.search_string().len()); + if !self.history_search.is_at_present() { + let new_text = self.history_search.current_result().to_owned(); + if self.history_search.by_token() { + self.replace_current_token(new_text); + } else { + self.replace_substring( + EditableLineTag::Commandline, + 0..self.command_line.len(), + new_text, + ); + if self.history_search.by_prefix() { + self.command_line + .set_position(self.history_search.search_string().len()); + } } + self.command_line_has_transient_edit = true; } - self.command_line_has_transient_edit = true; self.update_buff_pos(EditableLineTag::Commandline, None); } @@ -3034,12 +3032,10 @@ fn handle_readline_command(&mut self, c: ReadlineCmd) { }) } - if !found && !was_active_before { - self.history_search.reset(); - } else if found - || (dir == SearchDirection::Forward && self.history_search.is_at_present()) - { + if found { self.update_command_line_from_history_search(); + } else if !was_active_before { + self.history_search.reset(); } } rl::HistoryPager => { diff --git a/tests/checks/tmux-history-search2.fish b/tests/checks/tmux-history-search2.fish index d4b815647..d3fd421a7 100644 --- a/tests/checks/tmux-history-search2.fish +++ b/tests/checks/tmux-history-search2.fish @@ -4,11 +4,12 @@ isolated-tmux-start isolated-tmux send-keys ': 1' Enter -isolated-tmux send-keys ': ' M-Up M-Down M-Up M-Up M-Up Enter -isolated-tmux send-keys C-l 'echo still alive' Enter +isolated-tmux send-keys ': ' M-Up M-Down M-Up M-Up M-Up M-Down Enter +isolated-tmux send-keys 'echo still alive' Enter tmux-sleep -# isolated-tmux capture-pane -p | tail -2 isolated-tmux capture-pane -p +# CHECK: prompt 0> : 1 +# CHECK: prompt 1> : 1 # CHECK: prompt 2> echo still alive # CHECK: still alive # CHECK: prompt 3>