feat: cache current position to prevent unintuitive behavior
This commit is contained in:
parent
a2b3a84611
commit
3652a290b2
2 changed files with 22 additions and 9 deletions
|
@ -787,6 +787,7 @@ async fn main() -> Result<()> {
|
|||
}
|
||||
}
|
||||
tasks.custom_time = None;
|
||||
tasks.update_position();
|
||||
println!("{}", tasks);
|
||||
}
|
||||
Err(ReadlineError::Eof) => break 'repl,
|
||||
|
|
28
src/tasks.rs
28
src/tasks.rs
|
@ -75,15 +75,14 @@ pub(crate) struct TasksRelay {
|
|||
/// The task properties sorted by
|
||||
sorting: VecDeque<String>, // 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<EventId>,
|
||||
search_depth: usize,
|
||||
view_depth: usize,
|
||||
pub(crate) recurse_activities: bool,
|
||||
// Last position used in interface - needs auto-update
|
||||
//position: Option<EventId>,
|
||||
// Last visible position that intuitively interactions should be based on
|
||||
position: Option<EventId>,
|
||||
|
||||
/// Currently active tags
|
||||
tags: BTreeSet<Hashtag>,
|
||||
|
@ -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<EventId> {
|
||||
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<Timestamp> {
|
||||
|
@ -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(
|
||||
|
|
Loading…
Add table
Reference in a new issue