rmptui8a5c787
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.
+8 −1
1 file changed
- M src/event/handler.rs +8 −1
| @@ -159,13 +159,20 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { | |||
| 159 | 159 | ||
| 160 | 160 | // Delete highlighted song from the queue | |
| 161 | 161 | KeyCode::Char('d') => { | |
| 162 | − | if app.queue_list.index >= app.queue_list.list.len() - 1 | |
| 162 | + | if app.queue_list.index >= app.queue_list.list.len() | |
| 163 | 163 | && app.queue_list.index != 0 | |
| 164 | 164 | { | |
| 165 | 165 | app.queue_list.index -= 1; | |
| 166 | 166 | } | |
| 167 | 167 | ||
| 168 | 168 | app.conn.conn.delete(app.queue_list.index as u32)?; | |
| 169 | + | ||
| 170 | + | if app.queue_list.index >= app.queue_list.list.len().saturating_sub(1) | |
| 171 | + | && app.queue_list.index != 0 | |
| 172 | + | { | |
| 173 | + | app.queue_list.index -= 1; | |
| 174 | + | } | |
| 175 | + | ||
| 169 | 176 | app.update_queue(); | |
| 170 | 177 | } | |
| 171 | 178 | ||