summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-05-13 01:09:23 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-06-10 19:40:49 +0300
commit3bc22abdff69ee8d45c9bdb124c48884876dae1e (patch)
tree44e36cc8dc75dfc8f2b4791d1ae2b18b4e823879
parent2dec7fa6b6a4b011b03142e02b94c9a91e73fe3c (diff)
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.
-rw-r--r--melib/src/mailbox/thread.rs20
-rw-r--r--ui/src/components/mail/listing/thread.rs49
2 files changed, 31 insertions, 38 deletions
diff --git a/melib/src/mailbox/thread.rs b/melib/src/mailbox/thread.rs
index 763ba547..ac12fb60 100644
--- a/melib/src/mailbox/thread.rs
+++ b/melib/src/mailbox/thread.rs
@@ -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
}
diff --git a/ui/src/components/mail/listing/thread.rs b/ui/src/components/mail/listing/thread.rs
index d2d13740..65a51bac 100644
--- a/ui/src/components/mail/listing/thread.rs
+++ b/ui/src/components/mail/listing/thread.rs
@@ -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 {