From 7a411e269b59cb7754eadacaf29a18e02845040b Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 11 Nov 2021 04:36:09 -0500 Subject: handle the focused cursor being past the end of output --- src/history.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/history.rs') diff --git a/src/history.rs b/src/history.rs index e5ad161..348224b 100644 --- a/src/history.rs +++ b/src/history.rs @@ -127,10 +127,11 @@ impl History { &self, out: &mut textmode::Output, repl_lines: usize, + focus: Option, ) -> anyhow::Result<()> { let mut used_lines = repl_lines; let mut pos = None; - for entry in self.entries.iter().rev() { + for (idx, entry) in self.entries.iter().enumerate().rev() { let entry = entry.lock_arc().await; let screen = entry.vt.screen(); let mut last_row = 0; @@ -139,6 +140,12 @@ impl History { last_row = idx + 1; } } + if focus == Some(idx) { + last_row = std::cmp::max( + last_row, + screen.cursor_position().0 as usize + 1, + ); + } used_lines += 1 + std::cmp::min(6, last_row); if used_lines > 24 { break; -- cgit v1.2.3-54-g00ecf