From 7545d8466e81f6c0f5e857668454651214a6ce11 Mon Sep 17 00:00:00 2001 From: multiplex55 <6619098+multiplex55@users.noreply.github.com> Date: Sun, 1 Feb 2026 19:35:32 -0500 Subject: [PATCH] Fix todo tag empty filter --- src/plugins/todo.rs | 27 +++++++++++++++++++-------- tests/todo_plugin.rs | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/plugins/todo.rs b/src/plugins/todo.rs index ae37266d..2fd7a124 100644 --- a/src/plugins/todo.rs +++ b/src/plugins/todo.rs @@ -466,13 +466,24 @@ impl TodoPlugin { } // Otherwise, `todo tag []` lists all known tags and lets you drill into `todo list`. - let mut filter = rest; - if let Some(stripped) = filter.strip_prefix("tag:") { - filter = stripped.trim(); - } - if let Some(stripped) = filter.strip_prefix('#').or_else(|| filter.strip_prefix('@')) { - filter = stripped.trim(); - } + let filter = if rest.is_empty() { + None + } else { + let mut filter = rest; + if let Some(stripped) = filter.strip_prefix("tag:") { + filter = stripped.trim(); + } + if let Some(stripped) = + filter.strip_prefix('#').or_else(|| filter.strip_prefix('@')) + { + filter = stripped.trim(); + } + if filter.is_empty() { + None + } else { + Some(filter) + } + }; let guard = match self.data.read() { Ok(g) => g, @@ -497,7 +508,7 @@ impl TodoPlugin { .map(|(display, count)| (display, count)) .collect(); - if !filter.is_empty() { + if let Some(filter) = filter { tags.retain(|(tag, _)| self.matcher.fuzzy_match(tag, filter).is_some()); } diff --git a/tests/todo_plugin.rs b/tests/todo_plugin.rs index 0e6e9ea2..72783df6 100644 --- a/tests/todo_plugin.rs +++ b/tests/todo_plugin.rs @@ -297,6 +297,26 @@ fn tag_command_filters_by_tag() { assert_eq!(results[0].label, "#urgent (1)"); assert_eq!(results[0].action, "query:todo list #urgent"); } + +#[test] +fn tag_command_without_filter_lists_all_tags() { + let _lock = TEST_MUTEX.lock().unwrap(); + let dir = tempdir().unwrap(); + std::env::set_current_dir(dir.path()).unwrap(); + + append_todo(TODO_FILE, "alpha task", 1, &["alpha".into(), "beta".into()]).unwrap(); + append_todo(TODO_FILE, "beta task", 1, &["beta".into()]).unwrap(); + append_todo(TODO_FILE, "gamma task", 1, &["gamma".into(), "alpha".into()]).unwrap(); + + let plugin = TodoPlugin::default(); + let results = plugin.search("todo tag"); + let labels: Vec<&str> = results.iter().map(|action| action.label.as_str()).collect(); + + assert_eq!( + labels, + vec!["#alpha (2)", "#beta (2)", "#gamma (1)"] + ); +} #[test] fn search_view_opens_dialog() { let _lock = TEST_MUTEX.lock().unwrap();