From 8e3e107bdf627b25c934a17db4f1707acad7d4f1 Mon Sep 17 00:00:00 2001 From: anangryraven <39865912+AnAngryRaven@users.noreply.github.com> Date: Fri, 12 Sep 2025 08:48:35 -0400 Subject: [PATCH] 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 --- CHANGELOG.md | 1 + src/ui/queue.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 370b47f..d88fbe5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/src/ui/queue.rs b/src/ui/queue.rs index b64dbbd..2fe0a3c 100644 --- a/src/ui/queue.rs +++ b/src/ui/queue.rs @@ -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)); }