From cdd6981bf6cddb7cd6a636d76771e6ae364ba0bb Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Mon, 29 Jul 2024 13:37:05 +0300 Subject: [PATCH] feat(main): fallback to case-insensitive filter --- README.md | 9 ++++++--- src/main.rs | 13 ++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 40bedf7..85be5f1 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,15 @@ Recommendation: Flat hierarchy, using tags for filtering (TBI) ### Command Syntax -TASK add syntax: `NAME: TAG1 TAG2 ...` +`TASK` creation syntax: `NAME: TAG1 TAG2 ...` - `TASK` - create task - `.` - clear filters and reload -- `.TASK` - filter / activate (by id or name) / create & activate task -- `.NUM` - set view depth - how many subtask levels to show +- `.TASK` + + select task by id + + match by task name prefix: if one or more tasks match, filter / activate (tries case-sensitive then case-insensitive) + + no match: create & activate task +- `.2` - set view depth to `2`, which can be substituted for any number (how many subtask levels to show, default 1) Dots can be repeated to move to parent tasks diff --git a/src/main.rs b/src/main.rs index 547acd5..99b2661 100644 --- a/src/main.rs +++ b/src/main.rs @@ -294,12 +294,23 @@ async fn main() { // TODO check what is more intuitive: // currently resets filters before filtering again, maybe keep them tasks.move_to(pos); - let filtered: Vec = tasks + let mut filtered: Vec = tasks .current_tasks() .into_iter() .filter(|t| t.event.content.starts_with(slice)) .map(|t| t.event.id) .collect(); + if filtered.is_empty() { + let lowercase = slice.to_ascii_lowercase(); + filtered = tasks + .current_tasks() + .into_iter() + .filter(|t| { + t.event.content.to_ascii_lowercase().starts_with(&lowercase) + }) + .map(|t| t.event.id) + .collect(); + } match filtered.len() { 0 => { // No match, new task