fix: filter from correct position with multiple slashes

This commit is contained in:
xeruf 2024-11-09 19:36:06 +01:00
parent b9307b7b5d
commit ae525c870f
2 changed files with 8 additions and 7 deletions

View file

@ -741,7 +741,7 @@ async fn main() -> Result<()> {
} }
let filtered = let filtered =
tasks.get_filtered(|t| { tasks.get_filtered(pos, |t| {
transform(&t.event.content).contains(&remaining) || transform(&t.event.content).contains(&remaining) ||
t.tags.iter().flatten().any( t.tags.iter().flatten().any(
|tag| tag.content().is_some_and(|s| transform(s).contains(&remaining))) |tag| tag.content().is_some_and(|s| transform(s).contains(&remaining)))

View file

@ -490,7 +490,8 @@ impl TasksRelay {
current current
} }
pub(crate) fn visible_tasks(&self) -> Vec<&Task> { // TODO this is a relict for tests
fn visible_tasks(&self) -> Vec<&Task> {
if self.search_depth == 0 { if self.search_depth == 0 {
return vec![]; return vec![];
} }
@ -589,11 +590,11 @@ impl TasksRelay {
self.set_filter(|t| t.last_state_update() > time) self.set_filter(|t| t.last_state_update() > time)
} }
pub(crate) fn get_filtered<P>(&self, predicate: P) -> Vec<EventId> pub(crate) fn get_filtered<P>(&self, position: Option<&EventId>, predicate: P) -> Vec<EventId>
where where
P: Fn(&&Task) -> bool, P: Fn(&&Task) -> bool,
{ {
self.filtered_tasks(self.get_position_ref(), false) self.filtered_tasks(position, false)
.into_iter() .into_iter()
.filter(predicate) .filter(predicate)
.map(|t| t.event.id) .map(|t| t.event.id)
@ -604,7 +605,7 @@ impl TasksRelay {
where where
P: Fn(&&Task) -> bool, P: Fn(&&Task) -> bool,
{ {
self.set_view(self.get_filtered(predicate)) self.set_view(self.get_filtered(self.get_position_ref(), predicate))
} }
pub(crate) fn set_view_bookmarks(&mut self) -> bool { pub(crate) fn set_view_bookmarks(&mut self) -> bool {
@ -1158,8 +1159,8 @@ impl Display for TasksRelay {
} }
let position = self.get_position_ref(); let position = self.get_position_ref();
let mut current = vec![]; let mut current: Vec<&Task>;
let mut roots = self.view.iter().flat_map(|id| self.get_by_id(id)).collect_vec(); let roots = self.view.iter().flat_map(|id| self.get_by_id(id)).collect_vec();
if self.search_depth > 0 && roots.is_empty() { if self.search_depth > 0 && roots.is_empty() {
current = self.resolve_tasks_rec(self.tasks.children_for(position), true, self.search_depth + self.view_depth); current = self.resolve_tasks_rec(self.tasks.children_for(position), true, self.search_depth + self.view_depth);
if current.is_empty() { if current.is_empty() {