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.
This commit is contained in:
krolxon 2024-05-09 15:21:24 +05:30
parent 83c86d3c2d
commit 8a5c7877bd
1 changed files with 8 additions and 1 deletions

View File

@ -159,13 +159,20 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
// Delete highlighted song from the queue // Delete highlighted song from the queue
KeyCode::Char('d') => { 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 != 0
{ {
app.queue_list.index -= 1; app.queue_list.index -= 1;
} }
app.conn.conn.delete(app.queue_list.index as u32)?; 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(); app.update_queue();
} }