fix: do not crash when shift > queue len (#1705)
note this preserves behaviour of shifting by negative numbers in either direction changelog also updated accordingly
This commit is contained in:
committed by
Henrik Friedrichsen
parent
6799c188be
commit
8e3e107bdf
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Fixed
|
||||
|
||||
- Playlist retrieval crashing when list contains podcast episodes
|
||||
- Crash when shifting a song by an amount greater than the queue's length
|
||||
|
||||
## [1.3.1]
|
||||
|
||||
|
||||
@@ -162,13 +162,21 @@ impl ViewExt for QueueView {
|
||||
_ => 1,
|
||||
};
|
||||
|
||||
let mode = match mode {
|
||||
&ShiftMode::Up if amount.is_negative() => &ShiftMode::Down,
|
||||
&ShiftMode::Down if amount.is_negative() => &ShiftMode::Up,
|
||||
m => m,
|
||||
};
|
||||
|
||||
let amount = amount.abs();
|
||||
|
||||
let selected = self.list.get_selected_index();
|
||||
let len = self.queue.len();
|
||||
|
||||
match mode {
|
||||
ShiftMode::Up if selected > 0 => {
|
||||
self.queue
|
||||
.shift(selected, (selected as i32).saturating_sub(amount) as usize);
|
||||
.shift(selected, selected.saturating_sub(amount as usize));
|
||||
self.list.move_focus(-amount);
|
||||
return Ok(CommandResult::Consumed(None));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user