From c1c23269d2018c0d5125e839aaf7c03681cdfd77 Mon Sep 17 00:00:00 2001 From: kerty Date: Sun, 2 Feb 2025 23:40:38 +0300 Subject: [PATCH] Don't restart search if we maintain search mode Currently, the search always restarts when moving from the present. For example: 1. Do a few backward searches. 2. Use PageDown to return to the present. 3. Do another backward search. 4. Now, PageUp does nothing because the search was restarted, even if we maintained search mode. --- src/reader.rs | 8 +++----- src/reader_history_search.rs | 3 +++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/reader.rs b/src/reader.rs index 786b04cfd..7e6a65752 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -2982,7 +2982,7 @@ fn handle_readline_command(&mut self, c: ReadlineCmd) { let was_active_before = self.history_search.active(); - if self.history_search.is_at_present() { + if self.history_search.is_at_present() && mode != self.history_search.mode() { let el = &self.data.command_line; if mode == SearchMode::Token { // Searching by token. @@ -3331,15 +3331,13 @@ fn handle_readline_command(&mut self, c: ReadlineCmd) { }, false, ); - } else { + } else if self.history_search.active() { if up { self.history_search.go_to_oldest(); } else { self.history_search.go_to_present(); } - if self.history_search.active() { - self.update_command_line_from_history_search(); - } + self.update_command_line_from_history_search(); } } rl::UpLine | rl::DownLine => { diff --git a/src/reader_history_search.rs b/src/reader_history_search.rs index 1637a1e58..7c7acec2d 100644 --- a/src/reader_history_search.rs +++ b/src/reader_history_search.rs @@ -79,6 +79,9 @@ pub fn by_line(&self) -> bool { pub fn by_prefix(&self) -> bool { self.mode == SearchMode::Prefix } + pub fn mode(&self) -> SearchMode { + self.mode + } /// Move the history search in the given direction `dir`. pub fn move_in_direction(&mut self, dir: SearchDirection) -> bool {