From 4e965cba47fc871f06d4717f3db056a55f54f56a Mon Sep 17 00:00:00 2001 From: kerty Date: Wed, 15 Jan 2025 20:19:57 +0300 Subject: [PATCH] Separate SelectionMotion from HistoryPagerInvocation --- src/reader.rs | 15 ++++++++++----- src/reader_history_search.rs | 7 +++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/reader.rs b/src/reader.rs index d7778c49e..4695252b1 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -1271,6 +1271,7 @@ fn command_line_changed( if self.history_pager.is_some() { self.fill_history_pager( HistoryPagerInvocation::Anew, + Some(SelectionMotion::Next), SearchDirection::Backward, ); return; @@ -2723,6 +2724,7 @@ fn handle_readline_command(&mut self, c: ReadlineCmd) { } self.fill_history_pager( HistoryPagerInvocation::Advance, + Some(SelectionMotion::Next), SearchDirection::Forward, ); return; @@ -2992,6 +2994,7 @@ fn handle_readline_command(&mut self, c: ReadlineCmd) { } self.fill_history_pager( HistoryPagerInvocation::Advance, + Some(SelectionMotion::Next), SearchDirection::Backward, ); return; @@ -3071,6 +3074,7 @@ fn handle_readline_command(&mut self, c: ReadlineCmd) { self.history.save(); self.fill_history_pager( HistoryPagerInvocation::Refresh, + None, SearchDirection::Backward, ); } @@ -5150,6 +5154,7 @@ impl ReaderData { fn fill_history_pager( &mut self, why: HistoryPagerInvocation, + motion: Option, mut direction: SearchDirection, /* = Backward */ ) { let index; @@ -5171,7 +5176,7 @@ fn fill_history_pager( let history_pager = self.history_pager.as_ref().unwrap(); direction = SearchDirection::Backward; index = history_pager.start; - old_pager_index = Some(self.pager.selected_completion_index()); + old_pager_index = self.pager.selected_completion_index(); } } let search_term = self.pager.search_field_line.text().to_owned(); @@ -5208,11 +5213,11 @@ fn fill_history_pager( }; zelf.pager.set_completions(&result.matched_commands, false); if why == HistoryPagerInvocation::Refresh { - zelf.pager - .set_selected_completion_index(old_pager_index.unwrap()); + zelf.pager.set_selected_completion_index(old_pager_index); zelf.pager_selection_changed(); - } else { - zelf.select_completion_in_direction(SelectionMotion::Next, true); + } + if let Some(motion) = motion { + zelf.select_completion_in_direction(motion, true); } zelf.super_highlight_me_plenty(); zelf.layout_and_repaint(L!("history-pager")); diff --git a/src/reader_history_search.rs b/src/reader_history_search.rs index 551048cd8..eb37640fb 100644 --- a/src/reader_history_search.rs +++ b/src/reader_history_search.rs @@ -81,10 +81,9 @@ pub fn by_prefix(&self) -> bool { /// Move the history search in the given direction `dir`. pub fn move_in_direction(&mut self, dir: SearchDirection) -> bool { - if dir == SearchDirection::Forward { - self.move_forwards() - } else { - self.move_backwards() + match dir { + SearchDirection::Forward => self.move_forwards(), + SearchDirection::Backward => self.move_backwards(), } }