From 070000e1420ee85d8667129b7168854ba8342166 Mon Sep 17 00:00:00 2001 From: tbergerd <139167029+tbergerd@users.noreply.github.com> Date: Fri, 22 Sep 2023 00:15:51 +0200 Subject: [PATCH 1/2] Fix regression on Select which hides the prompt if there is only one page --- src/paging.rs | 17 +++++++++++------ src/prompts/select.rs | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/paging.rs b/src/paging.rs index 290c1d7f..f73d5eec 100644 --- a/src/paging.rs +++ b/src/paging.rs @@ -42,6 +42,16 @@ impl<'a> Paging<'a> { } } + pub fn update_page(&mut self, cursor_pos: usize) { + if cursor_pos != !0 + && (cursor_pos < self.current_page * self.capacity + || cursor_pos >= (self.current_page + 1) * self.capacity) + { + self.current_page = cursor_pos / self.capacity; + } + } + + /// Updates all internal based on the current terminal size and cursor position pub fn update(&mut self, cursor_pos: usize) -> Result { let new_term_size = self.term.size(); @@ -65,12 +75,7 @@ impl<'a> Paging<'a> { self.term.clear_last_lines(self.capacity)?; } - if cursor_pos != !0 - && (cursor_pos < self.current_page * self.capacity - || cursor_pos >= (self.current_page + 1) * self.capacity) - { - self.current_page = cursor_pos / self.capacity; - } + self.update_page(cursor_pos); Ok(()) } diff --git a/src/prompts/select.rs b/src/prompts/select.rs index 63b15d86..b932c6b8 100644 --- a/src/prompts/select.rs +++ b/src/prompts/select.rs @@ -214,7 +214,7 @@ impl Select<'_> { } term.hide_cursor()?; - paging.update(sel)?; + paging.update_page(sel); loop { if let Some(ref prompt) = self.prompt { From 339693bafa7941e403f45927c29760d406c69ba6 Mon Sep 17 00:00:00 2001 From: tbergerd <139167029+tbergerd@users.noreply.github.com> Date: Fri, 22 Sep 2023 00:27:44 +0200 Subject: [PATCH 2/2] Fix small cargo format-check violation --- src/paging.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/paging.rs b/src/paging.rs index f73d5eec..a02bfef8 100644 --- a/src/paging.rs +++ b/src/paging.rs @@ -50,7 +50,6 @@ impl<'a> Paging<'a> { self.current_page = cursor_pos / self.capacity; } } - /// Updates all internal based on the current terminal size and cursor position pub fn update(&mut self, cursor_pos: usize) -> Result {