Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Sep 28, 2024
1 parent eb2a404 commit 2dfe280
Showing 1 changed file with 43 additions and 38 deletions.
81 changes: 43 additions & 38 deletions crates/ui/src/input/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,42 +991,6 @@ impl Element for TextElement {
(text, cx.theme().foreground)
};

let run = TextRun {
len: display_text.len(),
font: style.font(),
color: text_color,
background_color: None,
underline: None,
strikethrough: None,
};

let runs = if let Some(marked_range) = input.marked_range.as_ref() {
vec![
TextRun {
len: marked_range.start,
..run.clone()
},
TextRun {
len: marked_range.end - marked_range.start,
underline: Some(UnderlineStyle {
color: Some(run.color),
thickness: px(1.0),
wavy: false,
}),
..run.clone()
},
TextRun {
len: display_text.len() - marked_range.end,
..run.clone()
},
]
.into_iter()
.filter(|run| run.len > 0)
.collect()
} else {
vec![run]
};

let font_size = style.font_size.to_pixels(cx.rem_size());
// Calculate the scroll offset to keep the cursor in view
let mut scroll_offset = input.scroll_offset;
Expand All @@ -1036,6 +1000,38 @@ impl Element for TextElement {
let mut last_layout = LastLayout { lines: vec![] };

for line_text in display_text.split("\n") {
let run = TextRun {
len: line_text.len(),
font: style.font(),
color: text_color,
background_color: None,
underline: None,
strikethrough: None,
};

let runs = if let Some(marked_range) = input.marked_range.as_ref() {
vec![
TextRun {
len: marked_range.start,
..run.clone()
},
TextRun {
len: marked_range.end - marked_range.start,
underline: Some(UnderlineStyle {
color: Some(run.color),
thickness: px(1.0),
wavy: false,
}),
..run.clone()
},
]
.into_iter()
.filter(|run| run.len > 0)
.collect()
} else {
vec![run]
};

let line = cx
.text_system()
.shape_line(SharedString::from(line_text.to_string()), font_size, &runs)
Expand Down Expand Up @@ -1136,8 +1132,17 @@ impl Element for TextElement {

let last_layout = prepaint.last_layout.take();
if let Some(last_layout) = last_layout {
for line in last_layout.lines.iter() {
line.paint(bounds.origin, cx.line_height(), cx).unwrap();
for (i, line) in last_layout.lines.iter().enumerate() {
let y = bounds.origin.y + i as f32 * cx.line_height();
line.paint(
Point {
x: bounds.origin.x,
y,
},
cx.line_height(),
cx,
)
.unwrap();
}
}

Expand Down

0 comments on commit 2dfe280

Please sign in to comment.