Skip to content

Commit 2e7c7b6

Browse files
authored
Merge pull request #792 from multiplex55/codex/update-todo-tag-handler-for-empty-filter
Fix todo tag listing for empty filters
2 parents 85808db + 7545d84 commit 2e7c7b6

2 files changed

Lines changed: 39 additions & 8 deletions

File tree

src/plugins/todo.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -466,13 +466,24 @@ impl TodoPlugin {
466466
}
467467

468468
// Otherwise, `todo tag [<filter>]` lists all known tags and lets you drill into `todo list`.
469-
let mut filter = rest;
470-
if let Some(stripped) = filter.strip_prefix("tag:") {
471-
filter = stripped.trim();
472-
}
473-
if let Some(stripped) = filter.strip_prefix('#').or_else(|| filter.strip_prefix('@')) {
474-
filter = stripped.trim();
475-
}
469+
let filter = if rest.is_empty() {
470+
None
471+
} else {
472+
let mut filter = rest;
473+
if let Some(stripped) = filter.strip_prefix("tag:") {
474+
filter = stripped.trim();
475+
}
476+
if let Some(stripped) =
477+
filter.strip_prefix('#').or_else(|| filter.strip_prefix('@'))
478+
{
479+
filter = stripped.trim();
480+
}
481+
if filter.is_empty() {
482+
None
483+
} else {
484+
Some(filter)
485+
}
486+
};
476487

477488
let guard = match self.data.read() {
478489
Ok(g) => g,
@@ -497,7 +508,7 @@ impl TodoPlugin {
497508
.map(|(display, count)| (display, count))
498509
.collect();
499510

500-
if !filter.is_empty() {
511+
if let Some(filter) = filter {
501512
tags.retain(|(tag, _)| self.matcher.fuzzy_match(tag, filter).is_some());
502513
}
503514

tests/todo_plugin.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,26 @@ fn tag_command_filters_by_tag() {
297297
assert_eq!(results[0].label, "#urgent (1)");
298298
assert_eq!(results[0].action, "query:todo list #urgent");
299299
}
300+
301+
#[test]
302+
fn tag_command_without_filter_lists_all_tags() {
303+
let _lock = TEST_MUTEX.lock().unwrap();
304+
let dir = tempdir().unwrap();
305+
std::env::set_current_dir(dir.path()).unwrap();
306+
307+
append_todo(TODO_FILE, "alpha task", 1, &["alpha".into(), "beta".into()]).unwrap();
308+
append_todo(TODO_FILE, "beta task", 1, &["beta".into()]).unwrap();
309+
append_todo(TODO_FILE, "gamma task", 1, &["gamma".into(), "alpha".into()]).unwrap();
310+
311+
let plugin = TodoPlugin::default();
312+
let results = plugin.search("todo tag");
313+
let labels: Vec<&str> = results.iter().map(|action| action.label.as_str()).collect();
314+
315+
assert_eq!(
316+
labels,
317+
vec!["#alpha (2)", "#beta (2)", "#gamma (1)"]
318+
);
319+
}
300320
#[test]
301321
fn search_view_opens_dialog() {
302322
let _lock = TEST_MUTEX.lock().unwrap();

0 commit comments

Comments
 (0)