Compare commits

...

2 Commits

Author SHA1 Message Date
Kate
b72672f3cf wip
Co-authored-by: John Tur <john-tur@outlook.com>
2025-10-16 19:06:37 +02:00
Kate
1b1bb1c7c6 Round the scroll offset in editor to fix jumping text
Co-authored-by: John Tur <john-tur@outlook.com>
2025-10-16 18:09:48 +02:00
4 changed files with 28 additions and 7 deletions

View File

@@ -7212,9 +7212,16 @@ impl EditorElement {
* ScrollPixelOffset::from(max_glyph_advance)
- ScrollPixelOffset::from(delta.x * scroll_sensitivity))
/ ScrollPixelOffset::from(max_glyph_advance);
let y = (current_scroll_position.y * ScrollPixelOffset::from(line_height)
let scale_factor = window.scale_factor();
let y = (current_scroll_position.y
* ScrollPixelOffset::from(line_height)
* ScrollPixelOffset::from(scale_factor)
- ScrollPixelOffset::from(delta.y * scroll_sensitivity))
/ ScrollPixelOffset::from(line_height);
.round()
/ ScrollPixelOffset::from(line_height)
/ ScrollPixelOffset::from(scale_factor);
let mut scroll_position =
point(x, y).clamp(&point(0., 0.), &position_map.scroll_max);
let forbid_vertical_scroll = editor.scroll_manager.forbid_vertical_scroll();

View File

@@ -2679,6 +2679,15 @@ impl Pixels {
Self(self.0.floor())
}
/// Rounds the `Pixels` value to the nearest pixel accounting for scaling.
///
/// # Returns
///
/// Returns a new `Pixels` instance with the rounded value.
pub fn round_pixel(&self, scale_factor: f32) -> Self {
Self((self.0 * scale_factor).round() / scale_factor)
}
/// Rounds the `Pixels` value to the nearest whole number.
///
/// # Returns

View File

@@ -196,8 +196,9 @@ fn paint_line(
window: &mut Window,
cx: &mut App,
) -> Result<()> {
let scale_factor = window.scale_factor();
let line_bounds = Bounds::new(
origin,
point(origin.x, origin.y.round_pixel(scale_factor)),
size(
layout.width,
line_height * (wrap_boundaries.len() as f32 + 1.),
@@ -205,7 +206,6 @@ fn paint_line(
);
window.paint_layer(line_bounds, |window| {
let padding_top = (line_height - layout.ascent - layout.descent) / 2.;
let baseline_offset = point(px(0.), padding_top + layout.ascent);
let mut decoration_runs = decoration_runs.iter();
let mut wraps = wrap_boundaries.iter().peekable();
let mut run_end = 0;
@@ -213,6 +213,11 @@ fn paint_line(
let mut current_underline: Option<(Point<Pixels>, UnderlineStyle)> = None;
let mut current_strikethrough: Option<(Point<Pixels>, StrikethroughStyle)> = None;
let text_system = cx.text_system().clone();
let scale_factor = window.scale_factor();
let baseline_offset = point(
px(0.),
(padding_top + layout.ascent).round_pixel(scale_factor),
);
let mut glyph_origin = point(
aligned_origin_x(
origin,
@@ -222,7 +227,7 @@ fn paint_line(
layout,
wraps.peek(),
),
origin.y,
origin.y.round_pixel(scale_factor),
);
let mut prev_glyph_position = Point::default();
let mut max_glyph_size = size(px(0.), px(0.));
@@ -273,7 +278,7 @@ fn paint_line(
layout,
wraps.peek(),
);
glyph_origin.y += line_height;
glyph_origin.y = (glyph_origin.y + line_height).round_pixel(scale_factor);
}
prev_glyph_position = glyph.position;

View File

@@ -2982,7 +2982,7 @@ impl Window {
})?
.expect("Callback above only errors or returns Some");
let bounds = Bounds {
origin: glyph_origin.map(|px| px.floor()) + raster_bounds.origin.map(Into::into),
origin: glyph_origin + raster_bounds.origin.map(Into::into),
size: tile.bounds.size.map(Into::into),
};
let content_mask = self.content_mask().scale(scale_factor);