Fix message order and cursor movement
This commit is contained in:
parent
8cbdc89b7e
commit
b918f0f31f
3 changed files with 13 additions and 3 deletions
|
|
@ -111,7 +111,7 @@ impl<M: Msg> TreeView<M> {
|
|||
let path = store.path(room, &cursor.id).await;
|
||||
let tree = store.tree(room, path.first()).await;
|
||||
if let Some(prev_sibling) = tree.prev_sibling(&cursor.id) {
|
||||
cursor.id = prev_sibling.clone();
|
||||
cursor.id = tree.last_child(prev_sibling.clone());
|
||||
return;
|
||||
} else if let Some(parent) = tree.parent(&cursor.id) {
|
||||
cursor.id = parent;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
pub mod dummy;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use chrono::{DateTime, Utc};
|
||||
|
||||
pub trait Msg {
|
||||
type Id: Clone + Hash + Eq;
|
||||
type Id: Clone + Debug + Hash + Eq + Ord;
|
||||
fn id(&self) -> Self::Id;
|
||||
fn parent(&self) -> Option<Self::Id>;
|
||||
|
||||
|
|
@ -63,6 +64,10 @@ impl<M: Msg> Tree<M> {
|
|||
}
|
||||
}
|
||||
|
||||
for list in children.values_mut() {
|
||||
list.sort_unstable();
|
||||
}
|
||||
|
||||
Self {
|
||||
root,
|
||||
msgs,
|
||||
|
|
|
|||
|
|
@ -46,7 +46,12 @@ impl Ui {
|
|||
let store = DummyStore::new()
|
||||
.msg(DummyMsg::new(1, "nick", "content"))
|
||||
.msg(DummyMsg::new(2, "Some1Else", "reply").parent(1))
|
||||
.msg(DummyMsg::new(4, "nick", "reply to nothing").parent(3));
|
||||
.msg(DummyMsg::new(3, "Some1Else", "deeper reply").parent(2))
|
||||
.msg(DummyMsg::new(4, "abc123", "even deeper reply").parent(3))
|
||||
.msg(DummyMsg::new(5, "Some1Else", "another reply").parent(1))
|
||||
.msg(DummyMsg::new(7, "nick", "reply to nothing").parent(6))
|
||||
.msg(DummyMsg::new(8, "nick", "another reply to nothing").parent(6))
|
||||
.msg(DummyMsg::new(9, "abc123", "reply to reply to nothing").parent(7));
|
||||
let chat = Chat::new(store, "testroom".to_string());
|
||||
|
||||
// Run main UI.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue