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
+1 -1
View File
@@ -249,7 +249,7 @@ impl RenderOnce for KeybindingHint {
blur_radius: px(0.),
spread_radius: px(0.),
}])
.child(self.keybinding.size(rems_from_px(kb_size.0))),
.child(self.keybinding.size(rems_from_px(kb_size))),
)
.children(self.suffix)
}
@@ -16,7 +16,7 @@ impl ListBulletItem {
impl RenderOnce for ListBulletItem {
fn render(self, window: &mut Window, _cx: &mut App) -> impl IntoElement {
let line_height = 0.85 * window.line_height();
let line_height = window.line_height() * 0.85;
ListItem::new("list-item")
.selectable(false)
+2 -2
View File
@@ -140,8 +140,8 @@ impl TextSize {
Self::Default => rems_from_px(14.),
Self::Small => rems_from_px(12.),
Self::XSmall => rems_from_px(10.),
Self::Ui => rems_from_px(theme_settings.ui_font_size(cx).into()),
Self::Editor => rems_from_px(theme_settings.buffer_font_size(cx).into()),
Self::Ui => rems_from_px(theme_settings.ui_font_size(cx)),
Self::Editor => rems_from_px(theme_settings.buffer_font_size(cx)),
}
}
}
+2 -2
View File
@@ -10,8 +10,8 @@ pub const BASE_REM_SIZE_IN_PX: f32 = 16.;
///
/// For instance, instead of writing `rems(0.875)` you can write `rems_from_px(14.)`
#[inline(always)]
pub fn rems_from_px(px: f32) -> Rems {
rems(px / BASE_REM_SIZE_IN_PX)
pub fn rems_from_px(px: impl Into<f32>) -> Rems {
rems(px.into() / BASE_REM_SIZE_IN_PX)
}
/// Returns a [`Length`] corresponding to the specified percentage of the viewport's width.
+5 -5
View File
@@ -1,20 +1,20 @@
use gpui::Pixels;
use gpui::{Pixels, px};
pub struct SearchInputWidth;
impl SearchInputWidth {
/// The container size in which the input stops filling the whole width.
pub const THRESHOLD_WIDTH: f32 = 1200.0;
pub const THRESHOLD_WIDTH: Pixels = px(1200.0);
/// The maximum width for the search input when the container is larger than the threshold.
pub const MAX_WIDTH: f32 = 1200.0;
pub const MAX_WIDTH: Pixels = px(1200.0);
/// Calculates the actual width in pixels based on the container width.
pub fn calc_width(container_width: Pixels) -> Pixels {
if container_width.0 < Self::THRESHOLD_WIDTH {
if container_width < Self::THRESHOLD_WIDTH {
container_width
} else {
Pixels(container_width.0.min(Self::MAX_WIDTH))
container_width.min(Self::MAX_WIDTH)
}
}
}