forked from janek/mostr
1
0
Fork 0

feat: properly include tasks with hashtags in filters

This commit is contained in:
xeruf 2024-09-14 16:06:47 +03:00
parent ddb68f7107
commit 0744e86922
2 changed files with 11 additions and 7 deletions

View File

@ -78,11 +78,14 @@ impl Task {
/// Trimmed event content or stringified id /// Trimmed event content or stringified id
pub(crate) fn get_title(&self) -> String { pub(crate) fn get_title(&self) -> String {
Some(self.event.content.trim().to_string()) some_non_empty(self.event.content.trim())
.filter(|s| !s.is_empty())
.unwrap_or_else(|| self.get_id().to_string()) .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<Item=&Event> + '_ { pub(crate) fn description_events(&self) -> impl Iterator<Item=&Event> + '_ {
self.props.iter().filter(|event| event.kind == Kind::TextNote) self.props.iter().filter(|event| event.kind == Kind::TextNote)
} }

View File

@ -670,20 +670,21 @@ impl Tasks {
let mut filtered: Vec<EventId> = Vec::with_capacity(32); let mut filtered: Vec<EventId> = Vec::with_capacity(32);
let mut filtered_fuzzy: Vec<EventId> = Vec::with_capacity(32); let mut filtered_fuzzy: Vec<EventId> = Vec::with_capacity(32);
for task in self.filtered_tasks(position, false) { 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 { if lowercase == lowercase_arg {
return vec![task.event.id]; return vec![task.event.id];
} else if task.event.content.starts_with(arg) { } else if content.starts_with(arg) {
filtered.push(task.event.id) 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) filtered_fuzzy.push(task.event.id)
} }
} }
for task in self.tasks.values() { for task in self.tasks.values() {
// Find global exact match // Find global exact match
if task.event.content.to_ascii_lowercase() == lowercase_arg && if task.get_filter_title().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 // 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]; return vec![task.event.id];
} }
} }