feat(main): fallback to case-insensitive filter

This commit is contained in:
xeruf 2024-07-29 13:37:05 +03:00
parent e255ce0676
commit cdd6981bf6
2 changed files with 18 additions and 4 deletions

View File

@ -24,12 +24,15 @@ Recommendation: Flat hierarchy, using tags for filtering (TBI)
### Command Syntax ### Command Syntax
TASK add syntax: `NAME: TAG1 TAG2 ...` `TASK` creation syntax: `NAME: TAG1 TAG2 ...`
- `TASK` - create task - `TASK` - create task
- `.` - clear filters and reload - `.` - clear filters and reload
- `.TASK` - filter / activate (by id or name) / create & activate task - `.TASK`
- `.NUM` - set view depth - how many subtask levels to show + 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 Dots can be repeated to move to parent tasks

View File

@ -294,12 +294,23 @@ async fn main() {
// TODO check what is more intuitive: // TODO check what is more intuitive:
// currently resets filters before filtering again, maybe keep them // currently resets filters before filtering again, maybe keep them
tasks.move_to(pos); tasks.move_to(pos);
let filtered: Vec<EventId> = tasks let mut filtered: Vec<EventId> = tasks
.current_tasks() .current_tasks()
.into_iter() .into_iter()
.filter(|t| t.event.content.starts_with(slice)) .filter(|t| t.event.content.starts_with(slice))
.map(|t| t.event.id) .map(|t| t.event.id)
.collect(); .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() { match filtered.len() {
0 => { 0 => {
// No match, new task // No match, new task