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 path = store.path(room, &cursor.id).await;
|
||||||
let tree = store.tree(room, path.first()).await;
|
let tree = store.tree(room, path.first()).await;
|
||||||
if let Some(prev_sibling) = tree.prev_sibling(&cursor.id) {
|
if let Some(prev_sibling) = tree.prev_sibling(&cursor.id) {
|
||||||
cursor.id = prev_sibling.clone();
|
cursor.id = tree.last_child(prev_sibling.clone());
|
||||||
return;
|
return;
|
||||||
} else if let Some(parent) = tree.parent(&cursor.id) {
|
} else if let Some(parent) = tree.parent(&cursor.id) {
|
||||||
cursor.id = parent;
|
cursor.id = parent;
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,14 @@
|
||||||
pub mod dummy;
|
pub mod dummy;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::fmt::Debug;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
|
||||||
pub trait Msg {
|
pub trait Msg {
|
||||||
type Id: Clone + Hash + Eq;
|
type Id: Clone + Debug + Hash + Eq + Ord;
|
||||||
fn id(&self) -> Self::Id;
|
fn id(&self) -> Self::Id;
|
||||||
fn parent(&self) -> Option<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 {
|
Self {
|
||||||
root,
|
root,
|
||||||
msgs,
|
msgs,
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,12 @@ impl Ui {
|
||||||
let store = DummyStore::new()
|
let store = DummyStore::new()
|
||||||
.msg(DummyMsg::new(1, "nick", "content"))
|
.msg(DummyMsg::new(1, "nick", "content"))
|
||||||
.msg(DummyMsg::new(2, "Some1Else", "reply").parent(1))
|
.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());
|
let chat = Chat::new(store, "testroom".to_string());
|
||||||
|
|
||||||
// Run main UI.
|
// Run main UI.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue