refactor(tasks): simplify up_to back

This commit is contained in:
xeruf 2024-12-06 20:47:47 +01:00
parent 0c6ad19600
commit cf04d4d852

View file

@ -402,8 +402,11 @@ impl TasksRelay {
/// Move up `count` parent tasks from current position /// Move up `count` parent tasks from current position
pub(crate) fn up_by(&self, count: usize) -> Option<EventId> { pub(crate) fn up_by(&self, count: usize) -> Option<EventId> {
let pos = self.get_position(); let pos = self.get_position();
if count < 1 { return pos; } let mut result = pos.as_ref();
self.traverse_up_from(pos).nth(count - 1)?.parent_id().cloned() for _ in 0..count {
result = self.get_parent(result);
}
result.cloned()
} }
pub(crate) fn get_parent(&self, id: Option<&EventId>) -> Option<&EventId> { pub(crate) fn get_parent(&self, id: Option<&EventId>) -> Option<&EventId> {