ui: draw thread arrows correctly in other sortings
thread arrows in ThreadListing weren't drawn correctly when subsorting was changed (eg date -> subject) has_sibling was delegated to ThreadsIterator.embed
parent
2dec7fa6b6
commit
3bc22abdff
|
@ -241,8 +241,8 @@ pub struct ThreadsIterator<'a> {
|
|||
tree: Ref<'a, Vec<ThreadTree>>,
|
||||
}
|
||||
impl<'a> Iterator for ThreadsIterator<'a> {
|
||||
type Item = (usize, usize);
|
||||
fn next(&mut self) -> Option<(usize, usize)> {
|
||||
type Item = (usize, usize, bool);
|
||||
fn next(&mut self) -> Option<(usize, usize, bool)> {
|
||||
{
|
||||
let mut tree = &(*self.tree);
|
||||
for i in &self.stack {
|
||||
|
@ -256,7 +256,11 @@ impl<'a> Iterator for ThreadsIterator<'a> {
|
|||
}
|
||||
} else {
|
||||
debug_assert!(self.pos < tree.len());
|
||||
let ret = (self.stack.len(), tree[self.pos].id);
|
||||
let ret = (
|
||||
self.stack.len(),
|
||||
tree[self.pos].id,
|
||||
!tree.is_empty() && !self.stack.is_empty() && (self.pos != (tree.len() - 1)),
|
||||
);
|
||||
if !tree[self.pos].children.is_empty() {
|
||||
self.stack.push(self.pos);
|
||||
self.pos = 0;
|
||||
|
@ -1168,7 +1172,15 @@ impl Threads {
|
|||
|
||||
pub fn has_sibling(&self, i: usize) -> bool {
|
||||
if let Some(parent) = self[i].parent {
|
||||
self[parent].children.len() > 1
|
||||
let children = &self[parent].children;
|
||||
if children.is_empty() {
|
||||
return false;
|
||||
}
|
||||
let pos = children
|
||||
.iter()
|
||||
.position(|&x| x == i)
|
||||
.expect("Did not find node in parent!");
|
||||
pos != children.len() - 1
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
|
|
@ -155,27 +155,12 @@ impl ThreadListing {
|
|||
let mut iter = threads.threads_iter().peekable();
|
||||
/* This is just a desugared for loop so that we can use .peek() */
|
||||
let mut idx = 0;
|
||||
while let Some((indentation, i)) = iter.next() {
|
||||
while let Some((indentation, i, has_sibling)) = iter.next() {
|
||||
let thread_node = &thread_nodes[i];
|
||||
|
||||
if indentation == 0 {
|
||||
thread_idx += 1;
|
||||
}
|
||||
|
||||
match iter.peek() {
|
||||
Some((x, _)) if *x == indentation => {
|
||||
indentations.pop();
|
||||
indentations.push(true);
|
||||
}
|
||||
_ => {
|
||||
indentations.pop();
|
||||
indentations.push(false);
|
||||
}
|
||||
}
|
||||
if threads.has_sibling(i) {
|
||||
indentations.pop();
|
||||
indentations.push(true);
|
||||
}
|
||||
if thread_node.has_message() {
|
||||
let envelope: &Envelope = &mailbox.collection[&thread_node.message().unwrap()];
|
||||
self.locations.push(envelope.hash());
|
||||
|
@ -200,6 +185,7 @@ impl ThreadListing {
|
|||
threads,
|
||||
&indentations,
|
||||
self.length,
|
||||
has_sibling,
|
||||
// context.accounts[self.cursor_pos.0].backend.operation(envelope.hash())
|
||||
),
|
||||
&mut self.content,
|
||||
|
@ -212,26 +198,26 @@ impl ThreadListing {
|
|||
self.content[(x, idx)].set_ch(' ');
|
||||
self.content[(x, idx)].set_bg(bg_color);
|
||||
}
|
||||
idx += 1;
|
||||
} else {
|
||||
self.locations.push(0);
|
||||
for x in 0..MAX_COLS {
|
||||
self.content[(x, idx)].set_ch(' ');
|
||||
self.content[(x, idx)].set_bg(Color::Default);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
match iter.peek() {
|
||||
Some((x, _)) if *x > indentation => {
|
||||
indentations.push(false);
|
||||
Some((x, _, _)) if *x > indentation => {
|
||||
if debug!(has_sibling) {
|
||||
indentations.push(true);
|
||||
} else {
|
||||
indentations.push(false);
|
||||
}
|
||||
}
|
||||
Some((x, _)) if *x < indentation => {
|
||||
Some((x, _, _)) if *x < indentation => {
|
||||
for _ in 0..(indentation - *x) {
|
||||
indentations.pop();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
idx += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -381,30 +367,25 @@ impl ThreadListing {
|
|||
threads: &Threads,
|
||||
indentations: &[bool],
|
||||
idx_width: usize,
|
||||
has_sibling: bool,
|
||||
//op: Box<BackendOp>,
|
||||
) -> String {
|
||||
let has_sibling = threads.has_sibling(node_idx);
|
||||
let thread_node = &threads[node_idx];
|
||||
let has_parent = thread_node.has_parent();
|
||||
let show_subject = thread_node.show_subject();
|
||||
|
||||
let mut s = format!(
|
||||
"{}{}{} ",
|
||||
idx,
|
||||
" ".repeat(idx_width + 2 - (idx.to_string().chars().count())),
|
||||
ThreadListing::format_date(&envelope)
|
||||
);
|
||||
let mut s = format!("{}{}{} ", idx, " ", ThreadListing::format_date(&envelope));
|
||||
for i in 0..indent {
|
||||
if indentations.len() > i && indentations[i] {
|
||||
s.push('│');
|
||||
} else {
|
||||
} else if indentations.len() > i {
|
||||
s.push(' ');
|
||||
}
|
||||
if i > 0 {
|
||||
s.push(' ');
|
||||
}
|
||||
}
|
||||
if indent > 0 {
|
||||
if indent > 0 && (has_sibling || has_parent) {
|
||||
if has_sibling && has_parent {
|
||||
s.push('├');
|
||||
} else if has_sibling {
|
||||
|
|
Loading…
Reference in New Issue