aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crates/yt/src/storage/db/insert/playlist.rs48
1 files changed, 26 insertions, 22 deletions
diff --git a/crates/yt/src/storage/db/insert/playlist.rs b/crates/yt/src/storage/db/insert/playlist.rs
index dc474ce..2287db9 100644
--- a/crates/yt/src/storage/db/insert/playlist.rs
+++ b/crates/yt/src/storage/db/insert/playlist.rs
@@ -51,30 +51,34 @@ impl Playlist {
let index = usize::from(current_index);
let playlist_length = self.len();
- let index = match index.cmp(&playlist_length) {
- Ordering::Greater => {
- unreachable!(
- "The index '{index}' cannot exceed the \
+ if playlist_length == 0 {
+ // There are no new videos to mark focused.
+ } else {
+ let index = match index.cmp(&playlist_length) {
+ Ordering::Greater => {
+ unreachable!(
+ "The index '{index}' cannot exceed the \
playlist length '{playlist_length}' as indices are 0 based."
- );
- }
- Ordering::Less => {
- // The index is still valid.
- // Therefore, we keep the user at this position.
- index
- }
- Ordering::Equal => {
- // The index is pointing to the end of the playlist. We could either go the second
- // to last entry (i.e., one entry back) or wrap around to the start.
- // We wrap around.
- 0
- }
- };
+ );
+ }
+ Ordering::Less => {
+ // The index is still valid.
+ // Therefore, we keep the user at this position.
+ index
+ }
+ Ordering::Equal => {
+ // The index is pointing to the end of the playlist. We could either go the second
+ // to last entry (i.e., one entry back) or wrap around to the start.
+ // We wrap around.
+ 0
+ }
+ };
- let next = self
- .get_mut(PlaylistIndex::from(index))
- .expect("We checked that the index is still good");
- next.set_focused(true, ops);
+ let next = self
+ .get_mut(PlaylistIndex::from(index))
+ .expect("We checked that the index is still good");
+ next.set_focused(true, ops);
+ }
// Tell mpv about our decision.
self.resync_with_mpv(app, mpv)?;