diff --git a/src/main.rs b/src/main.rs index 0efd5a4..f774f3f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -787,6 +787,7 @@ async fn main() -> Result<()> { } } tasks.custom_time = None; + tasks.update_position(); println!("{}", tasks); } Err(ReadlineError::Eof) => break 'repl, diff --git a/src/tasks.rs b/src/tasks.rs index 488cbc6..0157c0e 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -75,15 +75,14 @@ pub(crate) struct TasksRelay { /// The task properties sorted by sorting: VecDeque, // TODO prefix +/- for asc/desc, no prefix for default - /// A filtered view of the current tasks. - /// Would like this to be Task references - /// but that doesn't work unless I start meddling with Rc everywhere. + /// Temporary filtered view of the current tasks. + /// Would like this to be Task references but that doesn't work unless I start meddling with Rc everywhere. view: Vec, search_depth: usize, view_depth: usize, pub(crate) recurse_activities: bool, - // Last position used in interface - needs auto-update - //position: Option, + // Last visible position that intuitively interactions should be based on + position: Option, /// Currently active tags tags: BTreeSet, @@ -195,6 +194,7 @@ impl TasksRelay { priority: None, keys: vec![sender.pubkey()], own_keys: vec![sender.pubkey()], + position: None, search_depth: 4, view_depth: 0, @@ -241,7 +241,19 @@ impl TasksRelay { fn own_key(&self) -> PublicKey { self.sender.pubkey() } pub(crate) fn get_position(&self) -> Option { - self.get_position_at(now()).1 + self.position + } + + // Update the current position + // Returns whether the position changed + pub(super) fn update_position(&mut self) -> bool { + let new_position = self.get_position_at(now()).1; + if new_position != self.position { + self.view.clear(); + self.position = new_position; + return true + } + false } pub(super) fn parse_tracking_stamp_relative(&self, input: &str) -> Option { @@ -991,7 +1003,6 @@ impl TasksRelay { return; } - self.view.clear(); let pos = self.get_position(); if target == pos { debug!("Flushing Tasks because of move in place"); @@ -1003,7 +1014,7 @@ impl TasksRelay { .and_then(|id| self.get_by_id(&id)) .is_some_and(|t| t.parent_id() == pos.as_ref()) { - // FIXME this triggers when moving up and into created task + // FIXME this triggers when moving up and into created task, making creation like '..task' not undoable debug!("Flushing Tasks because of move beyond child"); self.sender.flush(); } @@ -1014,6 +1025,7 @@ impl TasksRelay { .skip_while(|e| e.created_at.as_u64() > now.as_u64() + MAX_OFFSET) .count() as u64; if offset >= MAX_OFFSET { + // This is a very odd edge case when a user moves more than MAX_OFFSET times in MAX_OFFSET seconds so we reject warn!("Whoa you are moving around quickly! Give me a few seconds to process.") } self.submit( @@ -1021,7 +1033,7 @@ impl TasksRelay { .custom_created_at(now + offset), ); } - + // Updates pub(crate) fn make_event_tag_from_id(&self, id: EventId, marker: &str) -> Tag {