aboutsummaryrefslogtreecommitdiff
path: root/src/event/handler.rs
diff options
context:
space:
mode:
authorkrolxon <krolyxon@tutanota.com>2024-05-09 15:21:24 +0530
committerkrolxon <krolyxon@tutanota.com>2024-05-09 15:21:24 +0530
commit8a5c7877bde3d4842d2fd1669323d7a9244657bc (patch)
tree1d3091fb2a36ad6aded8af67486a6fec1bb1f9d2 /src/event/handler.rs
parent83c86d3c2d6fa06f035ba5326809e4c7adf8edbe (diff)
fix deleting from queue when only two elements
if you have only two songs in the queue right now, and you try to delete the second song, it deletes the first song instead.
Diffstat (limited to 'src/event/handler.rs')
-rwxr-xr-xsrc/event/handler.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/event/handler.rs b/src/event/handler.rs
index 0fb6460..2b2dff3 100755
--- a/src/event/handler.rs
+++ b/src/event/handler.rs
@@ -159,13 +159,20 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
// Delete highlighted song from the queue
KeyCode::Char('d') => {
- if app.queue_list.index >= app.queue_list.list.len() - 1
+ if app.queue_list.index >= app.queue_list.list.len()
&& app.queue_list.index != 0
{
app.queue_list.index -= 1;
}
app.conn.conn.delete(app.queue_list.index as u32)?;
+
+ if app.queue_list.index >= app.queue_list.list.len().saturating_sub(1)
+ && app.queue_list.index != 0
+ {
+ app.queue_list.index -= 1;
+ }
+
app.update_queue();
}