From cfb65af7aa6ca67633425af4dfdd0df7b862eb92 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Wed, 13 Nov 2024 15:46:39 -0800 Subject: [PATCH] fix: save columns on removal Fixes: https://github.com/damus-io/notedeck/issues/432 Signed-off-by: William Casarin --- src/app.rs | 2 -- src/column.rs | 22 +++++++--------------- src/nav.rs | 3 ++- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/app.rs b/src/app.rs index 6f233d5..d886b5d 100644 --- a/src/app.rs +++ b/src/app.rs @@ -513,8 +513,6 @@ fn update_damus(damus: &mut Damus, ctx: &egui::Context) { } damus.app_rect_handler.try_save_app_size(ctx); - - damus.columns.attempt_perform_deletion_request(); } fn process_event(damus: &mut Damus, _subid: &str, event: &str) { diff --git a/src/column.rs b/src/column.rs index f1d6128..8603620 100644 --- a/src/column.rs +++ b/src/column.rs @@ -61,7 +61,6 @@ pub struct Columns { /// The selected column for key navigation selected: i32, - should_delete_column_at_index: Option, } static UIDS: AtomicU32 = AtomicU32::new(0); @@ -207,22 +206,15 @@ impl Columns { self.selected += 1; } - pub fn request_deletion_at_index(&mut self, index: usize) { - self.should_delete_column_at_index = Some(index); - } - - pub fn attempt_perform_deletion_request(&mut self) { - if let Some(index) = self.should_delete_column_at_index { - if let Some((key, _)) = self.columns.get_index_mut(index) { - self.timelines.shift_remove(key); - } + pub fn delete_column(&mut self, index: usize) { + if let Some((key, _)) = self.columns.get_index_mut(index) { + self.timelines.shift_remove(key); + } - self.columns.shift_remove_index(index); - self.should_delete_column_at_index = None; + self.columns.shift_remove_index(index); - if self.columns.is_empty() { - self.new_column_picker(); - } + if self.columns.is_empty() { + self.new_column_picker(); } } diff --git a/src/nav.rs b/src/nav.rs index 96b0597..9dcf6ed 100644 --- a/src/nav.rs +++ b/src/nav.rs @@ -205,11 +205,12 @@ pub fn render_nav(col: usize, app: &mut Damus, ui: &mut egui::Ui) -> bool { if let Some(title_response) = nav_response.title_response { match title_response { TitleResponse::RemoveColumn => { - app.columns_mut().request_deletion_at_index(col); let tl = app.columns().find_timeline_for_column_index(col); if let Some(timeline) = tl { unsubscribe_timeline(app.ndb(), timeline); } + app.columns_mut().delete_column(col); + col_changed = true; } } }