Fix off by one with end of selection

This commit is contained in:
Jeremy Soller 2022-10-19 10:20:22 -06:00
parent 190b41f387
commit 66f9fea001
No known key found for this signature in database
GPG key ID: 87F211AF2BE4C2FE

View file

@ -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)
);
}
}
}