Skip to content

Commit

Permalink
Make underlines and strikethroughs respect align (#226)
Browse files Browse the repository at this point in the history
* fix: Make underlines and strikethroughs respect align

* refactor: Pass the whole text area into `.render_lines()`
  • Loading branch information
CosmicHorrorDev committed Feb 2, 2024
1 parent 637e599 commit 76e69de
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ impl Default for TextBox {
}
}

#[derive(Clone)]
pub struct CachedTextArea {
key: KeyHash,
left: f32,
Expand Down Expand Up @@ -297,6 +298,7 @@ impl TextBox {
screen_position: Point,
bounds: Size,
zoom: f32,
text_area: &CachedTextArea,
) -> Vec<Line> {
fn push_line_segment(
lines: &mut Vec<ThinLine>,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 76e69de

Please sign in to comment.