From 4f5141760a4d13752b5a9aa11fe46904c4842630 Mon Sep 17 00:00:00 2001 From: objz Date: Sun, 26 Jul 2026 19:24:39 +0200 Subject: [PATCH] fix(content): preserve entries across toggles --- src/tui/widgets/content/list.rs | 34 ++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/tui/widgets/content/list.rs b/src/tui/widgets/content/list.rs index 9871e56..6fd31f7 100644 --- a/src/tui/widgets/content/list.rs +++ b/src/tui/widgets/content/list.rs @@ -1947,9 +1947,11 @@ enum WatcherEventHandling { fn watcher_event_handling(kind: ¬ify::EventKind) -> WatcherEventHandling { match kind { notify::EventKind::Access(_) => WatcherEventHandling::Ignore, - notify::EventKind::Create(_) - | notify::EventKind::Modify(_) - | notify::EventKind::Remove(_) => WatcherEventHandling::Paths, + notify::EventKind::Create(_) | notify::EventKind::Remove(_) => WatcherEventHandling::Paths, + notify::EventKind::Modify(notify::event::ModifyKind::Name(_)) => { + WatcherEventHandling::Rescan + } + notify::EventKind::Modify(_) => WatcherEventHandling::Paths, notify::EventKind::Any | notify::EventKind::Other => WatcherEventHandling::Rescan, } } @@ -2146,8 +2148,8 @@ mod tests { use super::{ ContentListState, WatcherEventHandling, available_description_width, - description_text_width, diff_event_paths, ellipsize, load_provider_icon, - right_aligned_footer_spans, square_icon_columns, title_suffix_spans, + description_text_width, diff_directory, diff_event_paths, ellipsize, load_provider_icon, + read_dir_stems, right_aligned_footer_spans, square_icon_columns, title_suffix_spans, watcher_event_handling, }; @@ -2183,12 +2185,34 @@ mod tests { watcher_event_handling(¬ify::EventKind::Modify(notify::event::ModifyKind::Any)), WatcherEventHandling::Paths ); + assert_eq!( + watcher_event_handling(¬ify::EventKind::Modify(notify::event::ModifyKind::Name( + notify::event::RenameMode::Both + ))), + WatcherEventHandling::Rescan + ); assert_eq!( watcher_event_handling(¬ify::EventKind::Any), WatcherEventHandling::Rescan ); } + #[test] + fn content_watcher_keeps_a_renamed_disabled_entry() { + let temp = tempfile::tempdir().unwrap(); + let enabled = temp.path().join("example.jar"); + let disabled = temp.path().join("example.jar.disabled"); + std::fs::write(&enabled, b"mod").unwrap(); + let known = Arc::new(Mutex::new(read_dir_stems(temp.path(), ".jar"))); + + std::fs::rename(enabled, &disabled).unwrap(); + let diff = diff_directory(temp.path(), ".jar", None, &known).unwrap(); + + assert_eq!(diff.toggled, vec![("example".to_owned(), false, disabled)]); + assert!(diff.removed.is_empty()); + assert!(diff.added.is_empty()); + } + #[test] fn irrelevant_watcher_paths_do_not_emit_an_empty_diff() { let temp = tempfile::tempdir().unwrap();