fix saturation bug in index computation code

This commit is contained in:
bunnie 2025-05-21 18:22:30 +08:00
parent f6aa07c20f
commit 942a64ea3b

View file

@ -56,8 +56,9 @@ impl Repl {
// An index of -1 gives the most recent command.
// -2 would give the second most recent command
pub(crate) fn get_history(&mut self, index: isize) -> &str {
&self.history
[(self.history.len() as isize + index).max(0).min(self.history.len() as isize - 1) as usize]
&self.history[(self.history.len() as isize + index)
.max(0)
.min(self.history.len().saturating_sub(1) as isize) as usize]
.text
}