From 1eaa3f850b5c18fbed460ed8d1a3da7ac68fa822 Mon Sep 17 00:00:00 2001 From: Miel Peeters Date: Thu, 14 May 2026 15:53:51 +0200 Subject: [PATCH] fix: deduplicate history Now the page history isn't updated when you go to the page you're currently at. Before, when you pressed e.g. 'l' multiple times to go to the lyrics page, you needed to press 'Backspace' the same number of times to go back to where you came from. --- spotify_player/src/state/model.rs | 2 +- spotify_player/src/state/ui/mod.rs | 7 ++++++- spotify_player/src/state/ui/page.rs | 12 ++++++------ spotify_player/src/ui/single_line_input.rs | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/spotify_player/src/state/model.rs b/spotify_player/src/state/model.rs index 94777792..f5596eb7 100644 --- a/spotify_player/src/state/model.rs +++ b/spotify_player/src/state/model.rs @@ -224,7 +224,7 @@ pub struct PlaylistFolderNode { pub children: Vec, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] /// A Spotify category pub struct Category { pub id: String, diff --git a/spotify_player/src/state/ui/mod.rs b/spotify_player/src/state/ui/mod.rs index 27f7b9f1..a29e39ea 100644 --- a/spotify_player/src/state/ui/mod.rs +++ b/spotify_player/src/state/ui/mod.rs @@ -61,8 +61,13 @@ impl UIState { } pub fn new_page(&mut self, page: PageState) { - self.history.push(page); self.popup = None; + if let Some(current_page) = self.history.last() { + if &page == current_page { + return; + } + } + self.history.push(page); } /// Return whether there exists a focused popup. diff --git a/spotify_player/src/state/ui/page.rs b/spotify_player/src/state/ui/page.rs index 6239d1b0..90a93928 100644 --- a/spotify_player/src/state/ui/page.rs +++ b/spotify_player/src/state/ui/page.rs @@ -4,7 +4,7 @@ use crate::{ }; use ratatui::widgets::{ListState, TableState}; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub enum PageState { Library { state: LibraryPageUIState, @@ -50,7 +50,7 @@ pub enum PageType { Logs, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub struct LibraryPageUIState { pub playlist_list: ListState, pub saved_album_list: ListState, @@ -59,7 +59,7 @@ pub struct LibraryPageUIState { pub playlist_folder_id: usize, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub struct SearchPageUIState { pub track_list: ListState, pub album_list: ListState, @@ -70,13 +70,13 @@ pub struct SearchPageUIState { pub focus: SearchFocusState, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub enum ContextPageType { CurrentPlaying, Browsing(ContextId), } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub enum ContextPageUIState { Playlist { track_table: TableState, @@ -123,7 +123,7 @@ pub enum SearchFocusState { Episodes, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub enum BrowsePageUIState { CategoryList { state: ListState, diff --git a/spotify_player/src/ui/single_line_input.rs b/spotify_player/src/ui/single_line_input.rs index c3b9c504..987b382c 100644 --- a/spotify_player/src/ui/single_line_input.rs +++ b/spotify_player/src/ui/single_line_input.rs @@ -4,7 +4,7 @@ use ratatui::widgets::Widget; use super::{Line, Modifier, Paragraph, Span, Style}; use crate::key::Key; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct LineInput { // This is less space-efficient than String, but it's easier to work with text manipulation at the // cursor. Otherwise, you have to shuffle back and forth between String and String::chars().