Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/plugins/todo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,24 @@ impl TodoPlugin {
}

// Otherwise, `todo tag [<filter>]` 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,
Expand All @@ -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());
}

Expand Down
20 changes: 20 additions & 0 deletions tests/todo_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down