From 66f9fea001dbc64bb328d78f4f2792d8dd94b8d6 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 19 Oct 2022 10:20:22 -0600 Subject: [PATCH] Fix off by one with end of selection --- src/buffer.rs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index 9f8edb5..0b901fc 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -511,23 +511,25 @@ impl<'a> TextBuffer<'a> { let end_glyph = if end.line == line_i_scrolled { end.glyph } else { - line.glyphs.len() + line.glyphs.len() + 1 }; - let start_x = line.glyphs.get(start_glyph).map_or(0, |glyph| { - glyph.x as i32 - }); - let end_x = line.glyphs.get(end_glyph).map_or(self.width, |glyph| { - (glyph.x + glyph.w) as i32 - }); + if end_glyph > start_glyph { + let start_x = line.glyphs.get(start_glyph).map_or(0, |glyph| { + glyph.x as i32 + }); + let end_x = line.glyphs.get(end_glyph - 1).map_or(self.width, |glyph| { + (glyph.x + glyph.w) as i32 + }); - f( - start_x, - line_y - font_size, - cmp::max(0, end_x - start_x) as u32, - line_height as u32, - 0x33_00_00_00 | (color & 0xFF_FF_FF) - ); + f( + start_x, + line_y - font_size, + cmp::max(0, end_x - start_x) as u32, + line_height as u32, + 0x33_00_00_00 | (color & 0xFF_FF_FF) + ); + } } }