editor: Fix scroll_beyond_last_line off for short files (#13571)
Release Notes: - Fixed bug with `scroll_beyond_last_line: off` for short files ([#13559](https://github.com/zed-industries/zed/issues/13559)).
This commit is contained in:
parent
45d4de75b3
commit
cb2d05b78f
2 changed files with 26 additions and 14 deletions
|
@ -1119,11 +1119,12 @@ impl EditorElement {
|
||||||
ScrollBeyondLastLine::Off => 1.0,
|
ScrollBeyondLastLine::Off => 1.0,
|
||||||
ScrollBeyondLastLine::VerticalScrollMargin => 1.0 + settings.vertical_scroll_margin,
|
ScrollBeyondLastLine::VerticalScrollMargin => 1.0 + settings.vertical_scroll_margin,
|
||||||
};
|
};
|
||||||
let total_rows = snapshot.max_point().row().as_f32() + scroll_beyond_last_line;
|
let total_rows =
|
||||||
|
(snapshot.max_point().row().as_f32() + scroll_beyond_last_line).max(rows_per_page);
|
||||||
let height = bounds.size.height;
|
let height = bounds.size.height;
|
||||||
let px_per_row = height / total_rows;
|
let px_per_row = height / total_rows;
|
||||||
let thumb_height = (rows_per_page * px_per_row).max(ScrollbarLayout::MIN_THUMB_HEIGHT);
|
let thumb_height = (rows_per_page * px_per_row).max(ScrollbarLayout::MIN_THUMB_HEIGHT);
|
||||||
let row_height = (height - thumb_height) / (total_rows - rows_per_page).max(0.0);
|
let row_height = (height - thumb_height) / (total_rows - rows_per_page).max(0.);
|
||||||
|
|
||||||
Some(ScrollbarLayout {
|
Some(ScrollbarLayout {
|
||||||
hitbox: cx.insert_hitbox(track_bounds, false),
|
hitbox: cx.insert_hitbox(track_bounds, false),
|
||||||
|
@ -4676,17 +4677,17 @@ impl Element for EditorElement {
|
||||||
text_hitbox.origin + point(gutter_dimensions.margin, Pixels::ZERO);
|
text_hitbox.origin + point(gutter_dimensions.margin, Pixels::ZERO);
|
||||||
|
|
||||||
let height_in_lines = bounds.size.height / line_height;
|
let height_in_lines = bounds.size.height / line_height;
|
||||||
|
let max_row = snapshot.max_point().row().as_f32();
|
||||||
let max_scroll_top = if matches!(snapshot.mode, EditorMode::AutoHeight { .. }) {
|
let max_scroll_top = if matches!(snapshot.mode, EditorMode::AutoHeight { .. }) {
|
||||||
(snapshot.max_point().row().as_f32() - height_in_lines + 1.).max(0.)
|
(max_row - height_in_lines + 1.).max(0.)
|
||||||
} else {
|
} else {
|
||||||
let settings = EditorSettings::get_global(cx);
|
let settings = EditorSettings::get_global(cx);
|
||||||
let max_row = snapshot.max_point().row().as_f32();
|
|
||||||
match settings.scroll_beyond_last_line {
|
match settings.scroll_beyond_last_line {
|
||||||
ScrollBeyondLastLine::OnePage => max_row,
|
ScrollBeyondLastLine::OnePage => max_row,
|
||||||
ScrollBeyondLastLine::Off => (max_row - height_in_lines + 1.0).max(0.0),
|
ScrollBeyondLastLine::Off => (max_row - height_in_lines + 1.).max(0.),
|
||||||
ScrollBeyondLastLine::VerticalScrollMargin => {
|
ScrollBeyondLastLine::VerticalScrollMargin => {
|
||||||
(max_row - height_in_lines + 1.0 + settings.vertical_scroll_margin)
|
(max_row - height_in_lines + 1. + settings.vertical_scroll_margin)
|
||||||
.max(0.0)
|
.max(0.)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -203,13 +203,24 @@ impl ScrollManager {
|
||||||
let scroll_top = scroll_position.y;
|
let scroll_top = scroll_position.y;
|
||||||
let scroll_top = match EditorSettings::get_global(cx).scroll_beyond_last_line {
|
let scroll_top = match EditorSettings::get_global(cx).scroll_beyond_last_line {
|
||||||
ScrollBeyondLastLine::OnePage => scroll_top,
|
ScrollBeyondLastLine::OnePage => scroll_top,
|
||||||
ScrollBeyondLastLine::Off => scroll_top
|
ScrollBeyondLastLine::Off => {
|
||||||
.min((map.max_buffer_row().as_f32()) - self.visible_line_count.unwrap() + 1.0),
|
if let Some(height_in_lines) = self.visible_line_count {
|
||||||
ScrollBeyondLastLine::VerticalScrollMargin => scroll_top.min(
|
let max_row = map.max_buffer_row().as_f32();
|
||||||
(map.max_buffer_row().as_f32()) - self.visible_line_count.unwrap()
|
scroll_top.min(max_row - height_in_lines + 1.).max(0.)
|
||||||
+ 1.0
|
} else {
|
||||||
+ self.vertical_scroll_margin,
|
scroll_top
|
||||||
),
|
}
|
||||||
|
}
|
||||||
|
ScrollBeyondLastLine::VerticalScrollMargin => {
|
||||||
|
if let Some(height_in_lines) = self.visible_line_count {
|
||||||
|
let max_row = map.max_buffer_row().as_f32();
|
||||||
|
scroll_top
|
||||||
|
.min(max_row - height_in_lines + 1. + self.vertical_scroll_margin)
|
||||||
|
.max(0.)
|
||||||
|
} else {
|
||||||
|
scroll_top
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let scroll_top_buffer_point =
|
let scroll_top_buffer_point =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue