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
14 changes: 11 additions & 3 deletions src/plugins/todo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ impl TodoPlugin {

fn search_internal(&self, trimmed: &str) -> Vec<Action> {
if let Some(rest) = crate::common::strip_prefix_ci(trimmed, "todo") {
if rest.is_empty() {
return vec![Action {
label: "todo: edit todos".into(),
desc: "Todo".into(),
action: "todo:dialog".into(),
args: None,
}];
}
if rest.trim().is_empty() {
let mut actions = vec![Action {
label: "todo: edit todos".into(),
Expand Down Expand Up @@ -604,7 +612,7 @@ impl Default for TodoPlugin {

impl Plugin for TodoPlugin {
fn search(&self, query: &str) -> Vec<Action> {
let trimmed = query.trim();
let trimmed = query.trim_start();
let key = trimmed.to_string();
if let Ok(mut cache) = self.cache.write() {
if let Some(res) = cache.get(&key).cloned() {
Expand Down Expand Up @@ -853,15 +861,15 @@ mod tests {
}

#[test]
fn todo_root_query_lists_subcommands_in_order() {
fn todo_root_query_with_space_lists_subcommands_in_order() {
let plugin = TodoPlugin {
matcher: SkimMatcherV2::default(),
data: TODO_DATA.clone(),
cache: TODO_CACHE.clone(),
watcher: None,
};

let actions = plugin.search_internal("todo");
let actions = plugin.search_internal("todo ");
let labels: Vec<&str> = actions.iter().map(|a| a.label.as_str()).collect();
let actions_list: Vec<&str> = actions.iter().map(|a| a.action.as_str()).collect();

Expand Down
36 changes: 19 additions & 17 deletions tests/todo_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,26 @@ fn search_plain_todo_opens_dialog() {
let _lock = TEST_MUTEX.lock().unwrap();
let plugin = TodoPlugin::default();
let results = plugin.search("todo");
assert_eq!(results.len(), 1);
assert_eq!(results[0].action, "todo:dialog");
}

#[test]
fn search_todo_space_shows_submenu() {
let _lock = TEST_MUTEX.lock().unwrap();
let plugin = TodoPlugin::default();
let results = plugin.search("todo ");
let labels: Vec<&str> = results.iter().map(|action| action.label.as_str()).collect();
let actions: Vec<&str> = results.iter().map(|action| action.action.as_str()).collect();
assert_eq!(
labels,
vec![
"todo: edit todos",
"todo edit",
"todo list",
"todo tag",
"todo view",
"todo add",
"todo rm",
"todo clear",
"todo pset",
"todo export",
]
);
assert_eq!(actions[0], "todo:dialog");
assert!(labels.contains(&"todo: edit todos"));
assert!(labels.contains(&"todo edit"));
assert!(labels.contains(&"todo list"));
assert!(labels.contains(&"todo tag"));
assert!(labels.contains(&"todo view"));
assert!(labels.contains(&"todo add"));
assert!(labels.contains(&"todo rm"));
assert!(labels.contains(&"todo clear"));
assert!(labels.contains(&"todo pset"));
assert!(labels.contains(&"todo export"));
}

#[test]
Expand Down