From 003d1d61204130a8339467604bfa767608c79799 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Thu, 29 Aug 2024 12:11:43 +0300 Subject: [PATCH] feat: prefer immediate children search results --- src/tasks.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/tasks.rs b/src/tasks.rs index 6a8b470..482beba 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -591,14 +591,22 @@ impl Tasks { } } for task in self.tasks.values() { + // Find global exact match if task.event.content.to_ascii_lowercase() == lowercase_arg && !self.traverse_up_from(Some(*task.get_id())).any(|t| t.pure_state() == State::Closed) { // exclude closed tasks and their subtasks return vec![task.event.id]; } } + if filtered.is_empty() { - return filtered_more; + filtered = filtered_more; + } + let pos = self.get_position_ref(); + let immediate = filtered.iter().filter( + |t| self.get_by_id(t).is_some_and(|t| t.parent_id() == pos)).collect_vec(); + if immediate.len() == 1 { + return immediate.into_iter().cloned().collect_vec(); } filtered }