mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
fix: out-of-bounds error with empty backstack (#2887)
This commit is contained in:
parent
a0ab614108
commit
c8148d2d75
1 changed files with 4 additions and 2 deletions
|
|
@ -41,7 +41,7 @@ impl<T: Eq + Clone> Backstack<T> {
|
|||
}
|
||||
|
||||
pub fn shift_forward(&mut self) -> Option<&T> {
|
||||
if self.cursor + 1 == self.stack.len() {
|
||||
if self.cursor + 1 >= self.stack.len() {
|
||||
None
|
||||
} else {
|
||||
self.cursor += 1;
|
||||
|
|
@ -56,7 +56,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_backstack() {
|
||||
let mut bs = Backstack::default();
|
||||
let mut bs: Backstack<u32> = Backstack::default();
|
||||
assert_eq!(bs.shift_forward(), None);
|
||||
|
||||
bs.push(&1);
|
||||
assert_eq!(bs.stack[bs.cursor], 1);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue