Handle single wrapped line scrolling
Before this change, scrolling down when there were multiple layout lines, that rendered beyond the screen, would not work properly. This is because the current logic only acts if there are two or more buffer lines, calculating the proper layout height for each line. This adds an edge case check for single lines, ensuring the case is handled.
This commit is contained in:
parent
81c9666eaa
commit
c8c8aa3fb8
1 changed files with 16 additions and 9 deletions
|
|
@ -343,18 +343,25 @@ impl Buffer {
|
|||
} else if let Some(height) = self.height_opt {
|
||||
// Adjust scroll forwards if cursor is after it
|
||||
let mut line_i = layout_cursor.line;
|
||||
while line_i > self.scroll.line {
|
||||
line_i -= 1;
|
||||
let layout = self
|
||||
.line_layout(font_system, line_i)
|
||||
.expect("shape_until_cursor failed to scroll forwards");
|
||||
for layout_line in layout.iter() {
|
||||
total_height += layout_line.line_height_opt.unwrap_or(metrics.line_height);
|
||||
}
|
||||
if line_i <= self.scroll.line {
|
||||
// This is a single line that may wrap
|
||||
if total_height > height + self.scroll.vertical {
|
||||
self.scroll.line = line_i;
|
||||
self.scroll.vertical = total_height - height;
|
||||
}
|
||||
} else {
|
||||
while line_i > self.scroll.line {
|
||||
line_i -= 1;
|
||||
let layout = self
|
||||
.line_layout(font_system, line_i)
|
||||
.expect("shape_until_cursor failed to scroll forwards");
|
||||
for layout_line in layout.iter() {
|
||||
total_height += layout_line.line_height_opt.unwrap_or(metrics.line_height);
|
||||
}
|
||||
if total_height > height + self.scroll.vertical {
|
||||
self.scroll.line = line_i;
|
||||
self.scroll.vertical = total_height - height;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue