From 0744e86922588ef6732f0cbc8f0462dfbbcc36fc Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Sat, 14 Sep 2024 16:06:47 +0300 Subject: [PATCH] feat: properly include tasks with hashtags in filters --- src/task.rs | 7 +++++-- src/tasks.rs | 11 ++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/task.rs b/src/task.rs index f121bc2..211c8d7 100644 --- a/src/task.rs +++ b/src/task.rs @@ -78,11 +78,14 @@ impl Task { /// Trimmed event content or stringified id pub(crate) fn get_title(&self) -> String { - Some(self.event.content.trim().to_string()) - .filter(|s| !s.is_empty()) + some_non_empty(self.event.content.trim()) .unwrap_or_else(|| self.get_id().to_string()) } + pub(crate) fn get_filter_title(&self) -> String { + self.event.content.trim().trim_start_matches('#').to_string() + } + pub(crate) fn description_events(&self) -> impl Iterator + '_ { self.props.iter().filter(|event| event.kind == Kind::TextNote) } diff --git a/src/tasks.rs b/src/tasks.rs index 837fedc..1ccd64b 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -670,20 +670,21 @@ impl Tasks { let mut filtered: Vec = Vec::with_capacity(32); let mut filtered_fuzzy: Vec = Vec::with_capacity(32); for task in self.filtered_tasks(position, false) { - let lowercase = task.event.content.to_ascii_lowercase(); + let content = task.get_filter_title(); + let lowercase = content.to_ascii_lowercase(); if lowercase == lowercase_arg { return vec![task.event.id]; - } else if task.event.content.starts_with(arg) { + } else if content.starts_with(arg) { filtered.push(task.event.id) - } else if if has_space { lowercase.starts_with(&lowercase_arg) } else { lowercase.split_ascii_whitespace().any(|word| word.starts_with(&lowercase_arg)) } { + } else if if has_space { lowercase.starts_with(&lowercase_arg) } else { lowercase.split_ascii_whitespace().any(|word| word.trim_start_matches('#').starts_with(&lowercase_arg)) } { filtered_fuzzy.push(task.event.id) } } 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) { + if task.get_filter_title().to_ascii_lowercase() == lowercase_arg && // exclude closed tasks and their subtasks + !self.traverse_up_from(Some(*task.get_id())).any(|t| t.pure_state() == State::Closed) { return vec![task.event.id]; } }