Skip to content

Commit

Permalink
Fix horizontal scrolling to start of empty line
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed May 30, 2024
1 parent cb9d405 commit b0a70c7
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,24 +378,25 @@ 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())
{
//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;
}
}
}
Expand Down

0 comments on commit b0a70c7

Please sign in to comment.