From b104a715442bbaad650b40d55095fbbe6dee56fd Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Fri, 26 Apr 2019 12:48:08 +0300 Subject: [PATCH] ui: highlight entries in ThreadView within grid boundaries If entry string length + indentation was more than available width an out of index panic occurs when opening the thread. --- ui/src/components/mail/view/thread.rs | 34 ++++++++++++++++++--------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/ui/src/components/mail/view/thread.rs b/ui/src/components/mail/view/thread.rs index 2b591dfc..684d3e33 100644 --- a/ui/src/components/mail/view/thread.rs +++ b/ui/src/components/mail/view/thread.rs @@ -301,7 +301,7 @@ impl ThreadView { false, ); if let Some(len) = highlight_reply_subjects[y] { - let index = e.index.0 * 4 + 1 + e.heading.grapheme_width() - len; + let index = e.index.0 * 4 + 1; let area = ((index, 2 * y), (width - 2, 2 * y)); let fg_color = Color::Byte(33); let bg_color = Color::Default; @@ -437,11 +437,17 @@ impl ThreadView { (visual_indentation, 2 * (self.cursor_pos - top_idx)), ), ( - get_x(upper_left) - + visual_indentation - + self.entries[idx].heading.grapheme_width() - + 1, - get_y(upper_left) + 2 * (self.cursor_pos - top_idx), + cmp::min( + get_x(bottom_right), + get_x(upper_left) + + visual_indentation + + self.entries[idx].heading.grapheme_width() + + 1, + ), + cmp::min( + get_y(bottom_right), + get_y(upper_left) + 2 * (self.cursor_pos - top_idx), + ), ), ); @@ -468,11 +474,17 @@ impl ThreadView { (visual_indentation, 2 * (visibles[..idx].len() - top_idx)), ), ( - get_x(upper_left) - + visual_indentation - + self.entries[entry_idx].heading.grapheme_width() - + 1, - get_y(upper_left) + 2 * (visibles[..idx].len() - top_idx), + cmp::min( + get_x(bottom_right), + get_x(upper_left) + + visual_indentation + + self.entries[entry_idx].heading.grapheme_width() + + 1, + ), + cmp::min( + get_y(bottom_right), + get_y(upper_left) + 2 * (visibles[..idx].len() - top_idx), + ), ), );