Fix horizontal scrolling to start of empty line

This commit is contained in:
Jeremy Soller 2024-05-30 14:36:18 -06:00
parent cb9d405c20
commit b0a70c70ff
No known key found for this signature in database
GPG key ID: D02FD439211AF56F

View file

@ -378,7 +378,7 @@ impl Buffer {
if let Some(layout_cursor) = self.layout_cursor(font_system, cursor) {
if let Some(layout_lines) = self.line_layout(font_system, layout_cursor.line) {
if let Some(layout_line) = layout_lines.get(layout_cursor.layout) {
if let Some(glyph) = layout_line
let (x_min, x_max) = if let Some(glyph) = layout_line
.glyphs
.get(layout_cursor.glyph)
.or_else(|| layout_line.glyphs.last())
@ -386,16 +386,17 @@ impl Buffer {
//TODO: use code from cursor_glyph_opt?
let x_a = glyph.x;
let x_b = glyph.x + glyph.w;
let x_min = x_a.min(x_b);
let x_max = x_a.max(x_b);
if x_min < self.scroll.horizontal {
self.scroll.horizontal = x_min;
self.redraw = true;
}
if x_max > self.scroll.horizontal + self.width {
self.scroll.horizontal = x_max - self.width;
self.redraw = true;
}
(x_a.min(x_b), x_a.max(x_b))
} else {
(0.0, 0.0)
};
if x_min < self.scroll.horizontal {
self.scroll.horizontal = x_min;
self.redraw = true;
}
if x_max > self.scroll.horizontal + self.width {
self.scroll.horizontal = x_max - self.width;
self.redraw = true;
}
}
}