editor: Represent scroll offset with more precision (#39367)

Closes #5355

Release Notes:

- Fixed rendering glitches with files with more than 16 million lines
(that occured due to floating number rounding errors).

---------

Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
This commit is contained in:
Piotr Osiewicz
2025-10-02 23:04:31 +02:00
committed by GitHub
co-authored by Smit Barmase
parent 4c35274b6e
commit d359a814f8
61 changed files with 711 additions and 530 deletions
+4 -4
View File
@@ -1573,12 +1573,12 @@ fn up_down_buffer_rows(
let (goal_wrap, goal_x) = match goal {
SelectionGoal::WrappedHorizontalPosition((row, x)) => (row, x),
SelectionGoal::HorizontalRange { end, .. } => (select_nth_wrapped_row, end),
SelectionGoal::HorizontalPosition(x) => (select_nth_wrapped_row, x),
SelectionGoal::HorizontalRange { end, .. } => (select_nth_wrapped_row, end as f32),
SelectionGoal::HorizontalPosition(x) => (select_nth_wrapped_row, x as f32),
_ => {
let x = map.x_for_display_point(point, text_layout_details);
goal = SelectionGoal::WrappedHorizontalPosition((select_nth_wrapped_row, x.0));
(select_nth_wrapped_row, x.0)
goal = SelectionGoal::WrappedHorizontalPosition((select_nth_wrapped_row, x.into()));
(select_nth_wrapped_row, x.into())
}
};
+3 -3
View File
@@ -121,9 +121,9 @@ fn scroll_editor(
let amount = match (amount.is_full_page(), editor.visible_line_count()) {
(true, Some(visible_line_count)) => {
if amount.direction().is_upwards() {
ScrollAmount::Line(amount.lines(visible_line_count) + 1.0)
ScrollAmount::Line((amount.lines(visible_line_count) + 1.0) as f32)
} else {
ScrollAmount::Line(amount.lines(visible_line_count) - 1.0)
ScrollAmount::Line((amount.lines(visible_line_count) - 1.0) as f32)
}
}
_ => amount,
@@ -308,7 +308,7 @@ mod test {
let window = cx.window;
let margin = cx
.update_window(window, |_, window, _cx| {
window.viewport_size().height - line_height * visible_line_count
window.viewport_size().height - line_height * visible_line_count as f32
})
.unwrap();
cx.simulate_window_resize(
@@ -277,7 +277,7 @@ impl NeovimBackedTestContext {
let window = self.window;
let margin = self
.update_window(window, |_, window, _cx| {
window.viewport_size().height - line_height * visible_line_count
window.viewport_size().height - line_height * (visible_line_count as f32)
})
.unwrap();
+3 -3
View File
@@ -314,7 +314,7 @@ impl Vim {
let (start, end) = match s.newest_anchor().goal {
SelectionGoal::HorizontalRange { start, end } if preserve_goal => (start, end),
SelectionGoal::HorizontalPosition(start) if preserve_goal => (start, start),
_ => (tail_x.0, head_x.0),
_ => (tail_x.into(), head_x.into()),
};
let mut goal = SelectionGoal::HorizontalRange { start, end };
@@ -359,8 +359,8 @@ impl Vim {
if !preserve_goal {
goal = SelectionGoal::HorizontalRange {
start: positions.start.0,
end: positions.end.0,
start: f64::from(positions.start),
end: f64::from(positions.end),
};
}