diff --git a/src/renderer.rs b/src/renderer.rs index 5894a6b5..102c8096 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -239,13 +239,14 @@ impl Renderer { f32::INFINITY, ); - text_areas.push(text_box.text_areas( + let areas = text_box.text_areas( &mut self.text_system, pos, bounds, self.zoom, self.scroll_y, - )); + ); + text_areas.push(areas.clone()); if text_box.is_code_block || text_box.is_quote_block.is_some() { let color = if let Some(bg_color) = text_box.background_color { bg_color @@ -328,6 +329,7 @@ impl Renderer { scrolled_pos, bounds, self.zoom, + &areas, ) { let min = (line.min.0, line.min.1); let max = (line.max.0, line.max.1 + 2. * self.hidpi_scale * self.zoom); diff --git a/src/text.rs b/src/text.rs index b55335a0..aa0de7ba 100644 --- a/src/text.rs +++ b/src/text.rs @@ -92,6 +92,7 @@ impl Default for TextBox { } } +#[derive(Clone)] pub struct CachedTextArea { key: KeyHash, left: f32, @@ -297,6 +298,7 @@ impl TextBox { screen_position: Point, bounds: Size, zoom: f32, + text_area: &CachedTextArea, ) -> Vec { fn push_line_segment( lines: &mut Vec, @@ -372,7 +374,7 @@ impl TextBox { let start_cursor = Cursor::new(line.line_i, range.start); let end_cursor = Cursor::new(line.line_i, range.end); if let Some((highlight_x, highlight_w)) = line.highlight(start_cursor, end_cursor) { - let x = screen_position.0 + highlight_x; + let x = text_area.left + highlight_x; let min = (x.floor(), y); let max = ((x + highlight_w).ceil(), y); let line = Line::with_color(min, max, *color);