view/thread.rs: fix expanded_hash argument off by one error

When calling ThreadView::new with an envelope hash, Some(expanded_hash),
in the arguments, when translating it to a cursor position (usize) it
was mistakenly subtracted with 1 resulting in the wrong thread entry
showing up as expanded.
pull/227/head
Manos Pitsidianakis 2023-06-16 21:24:04 +03:00
parent 45bac6eb16
commit fdc0861ac0
Signed by: Manos Pitsidianakis
GPG Key ID: 7729C7707F7E09D0
3 changed files with 16 additions and 10 deletions

View File

@ -103,16 +103,27 @@ impl<T> RowsState<T> {
entry_strings: EntryStrings,
) {
env_hashes.dedup();
env_hashes.retain(|h| !self.all_envelopes.contains(h));
if env_hashes.is_empty() {
return;
}
let index = self.entries.len();
self.thread_order.insert(thread, index);
self.all_threads.insert(thread);
for &env_hash in &env_hashes {
self.selection.insert(env_hash, false);
self.env_to_thread.insert(env_hash, thread);
self.env_order.insert(env_hash, index);
self.all_envelopes.insert(env_hash);
}
self.thread_to_env.insert(thread, env_hashes);
if !self.all_threads.contains(&thread) {
self.thread_order.insert(thread, index);
self.all_threads.insert(thread);
self.thread_to_env.insert(thread, env_hashes);
} else {
self.thread_to_env
.entry(thread)
.or_default()
.extend_from_slice(&env_hashes);
}
self.entries.push((metadata, entry_strings));
}

View File

@ -782,12 +782,7 @@ impl ThreadListing {
}
fn get_env_under_cursor(&self, cursor: usize) -> Option<EnvelopeHash> {
self.rows
.env_order
.iter()
.find(|(_, &r)| r == cursor)
.map(|v| v.0)
.cloned()
self.rows.entries.get(cursor).map(|v| (v.0).1)
}
fn make_entry_string(&self, e: &Envelope, context: &Context) -> EntryStrings {

View File

@ -231,7 +231,7 @@ impl ThreadView {
};
match expanded_hash {
Some(expanded_hash) if expanded_hash == entry.msg_hash => {
self.new_expanded_pos = self.entries.len().saturating_sub(1);
self.new_expanded_pos = self.entries.len();
self.expanded_pos = self.new_expanded_pos + 1;
}
_ => {}