Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Playlist: add shortcuts to jump to the start or the end
  • Loading branch information
BlackYoup committed Nov 28, 2019
commit a8edb7f51b70e154aaf0ee39ef23e1527ff42e33
62 changes: 61 additions & 1 deletion src/handlers/track_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,66 @@ pub fn handler(key: Key, app: &mut App) {
None => {}
};
}
Key::Ctrl('e') => jump_to_end(app),
Key::Ctrl('a') => jump_to_start(app),
_ => {}
};
}
}

fn jump_to_end(app: &mut App) {
match &app.track_table.context {
Some(context) => match context {
TrackTableContext::MyPlaylists => {
if let (Some(playlists), Some(selected_playlist_index)) =
(&app.playlists, &app.selected_playlist_index)
{
if let Some(selected_playlist) =
playlists.items.get(selected_playlist_index.to_owned())
{
let total_tracks = selected_playlist
.tracks
.get("total")
.and_then(|total| total.as_u64())
.expect("playlist.tracks object should have a total field")
as u32;

if app.large_search_limit < total_tracks {
app.playlist_offset =
total_tracks - (total_tracks % app.large_search_limit);
let playlist_id = selected_playlist.id.to_owned();
app.get_playlist_tracks(playlist_id);
}
}
}
}
TrackTableContext::SavedTracks => {}
TrackTableContext::AlbumSearch => {}
TrackTableContext::PlaylistSearch => {}
},
None => {}
}
}

fn jump_to_start(app: &mut App) {
match &app.track_table.context {
Some(context) => match context {
TrackTableContext::MyPlaylists => {
if let (Some(playlists), Some(selected_playlist_index)) =
(&app.playlists, &app.selected_playlist_index)
{
if let Some(selected_playlist) =
playlists.items.get(selected_playlist_index.to_owned())
{
app.playlist_offset = 0;
let playlist_id = selected_playlist.id.to_owned();
app.get_playlist_tracks(playlist_id);
}
}
}
TrackTableContext::SavedTracks => {}
TrackTableContext::AlbumSearch => {}
TrackTableContext::PlaylistSearch => {}
},
None => {}
}
}
2 changes: 2 additions & 0 deletions src/ui/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ pub fn get_help_docs() -> Vec<Vec<&'static str>> {
"<Ctrl+u>",
"Pagination",
],
vec!["Jump to start of playlist", "<Ctrl+a>", "Pagination"],
vec!["Jump to end of playlist", "<Ctrl+e>", "Pagination"],
vec!["Delete saved album", "D", "Library -> Albums"],
vec!["Follow an artists", "w", "Search result"],
]
Expand Down