From 1fd43eb6718b0abf0c58487b146e67bc789f3c8b Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Tue, 24 Jul 2018 01:35:45 +0300 Subject: [PATCH] Fix whitespace overflow in copy_area_with_break --- ui/src/components/mail/view.rs | 3 --- ui/src/components/mod.rs | 9 +++++++++ ui/src/components/utilities.rs | 5 +++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs index 90ba031c..19db0c49 100644 --- a/ui/src/components/mail/view.rs +++ b/ui/src/components/mail/view.rs @@ -145,9 +145,6 @@ impl Component for MailView { for c in c_slice[i..i+3].iter_mut() { c.set_fg(Color::Byte(226)); } - - - } }, _ => {}, diff --git a/ui/src/components/mod.rs b/ui/src/components/mod.rs index b7bb6b4a..4c9411e8 100644 --- a/ui/src/components/mod.rs +++ b/ui/src/components/mod.rs @@ -96,6 +96,15 @@ pub fn copy_area_with_break(grid_dest: &mut CellBuffer, grid_src: &CellBuffer, d 'y_: for y in get_y(upper_left!(dest))..=get_y(bottom_right!(dest)) { 'x_: for x in get_x(upper_left!(dest))..=get_x(bottom_right!(dest)) { + if grid_src[(src_x, src_y)].ch() == '\n' { + src_y += 1; + src_x = 0; + if src_y == get_y(bottom_right!(src)) { + break 'y_; + } + continue 'y_; + } + grid_dest[(x,y)] = grid_src[(src_x, src_y)]; if src_x == get_x(bottom_right!(src)) { src_y += 1; diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs index 70a23b50..c1cae74b 100644 --- a/ui/src/components/utilities.rs +++ b/ui/src/components/utilities.rs @@ -195,16 +195,17 @@ impl Pager { pub fn from_buf(buf: CellBuffer) -> Self { let lines: Vec<&[Cell]> = buf.split(|cell| cell.ch() == '\n').collect(); let height = lines.len(); - let width = lines.iter().map(|l| l.len()).max().unwrap_or(0); + let width = lines.iter().map(|l| l.len()).max().unwrap_or(0) + 1; let mut content = CellBuffer::new(width, height, Cell::with_char(' ')); { - let mut x = 0; + let mut x; let mut y = 0; let c_slice: &mut [Cell] = &mut content; for l in lines { let y_r = y * width; x = l.len() + y_r; c_slice[y_r..x].copy_from_slice(l); + c_slice[x].set_ch('\n'); y += 1; } }