input: Fix wrap text not draw in multi-line mode. (#998)
Close #997 https://github.com/user-attachments/assets/6ad9f431-b5a2-42f1-93e6-6425f0851898
This commit is contained in:
parent
7360d2834d
commit
3a6741f990
1 changed files with 8 additions and 5 deletions
|
|
@ -333,14 +333,15 @@ impl TextElement {
|
||||||
&self,
|
&self,
|
||||||
state: &InputState,
|
state: &InputState,
|
||||||
line_height: Pixels,
|
line_height: Pixels,
|
||||||
bounds: &Bounds<Pixels>,
|
input_height: Pixels,
|
||||||
) -> Range<usize> {
|
) -> Range<usize> {
|
||||||
if state.is_single_line() {
|
if state.is_single_line() {
|
||||||
return 0..1;
|
return 0..1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let scroll_top = -state.scroll_handle.offset().y;
|
let scroll_top = -state.scroll_handle.offset().y;
|
||||||
let mut visible_range = 0..state.text_wrapper.lines.len();
|
let total_lines = state.text_wrapper.lines.len();
|
||||||
|
let mut visible_range = 0..total_lines;
|
||||||
let mut line_top = px(0.);
|
let mut line_top = px(0.);
|
||||||
for (ix, line) in state.text_wrapper.lines.iter().enumerate() {
|
for (ix, line) in state.text_wrapper.lines.iter().enumerate() {
|
||||||
line_top += line.height(line_height);
|
line_top += line.height(line_height);
|
||||||
|
|
@ -348,8 +349,9 @@ impl TextElement {
|
||||||
if line_top < scroll_top {
|
if line_top < scroll_top {
|
||||||
visible_range.start = ix;
|
visible_range.start = ix;
|
||||||
}
|
}
|
||||||
if line_top > scroll_top + bounds.size.height {
|
|
||||||
visible_range.end = ix;
|
if line_top > scroll_top + input_height {
|
||||||
|
visible_range.end = (ix + 1).min(total_lines);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -536,7 +538,7 @@ impl Element for TextElement {
|
||||||
let state = self.input.read(cx);
|
let state = self.input.read(cx);
|
||||||
let line_height = window.line_height();
|
let line_height = window.line_height();
|
||||||
|
|
||||||
let visible_range = self.calculate_visible_range(&state, line_height, &bounds);
|
let visible_range = self.calculate_visible_range(&state, line_height, bounds.size.height);
|
||||||
let highlight_styles = self.highlight_lines(&visible_range, cx);
|
let highlight_styles = self.highlight_lines(&visible_range, cx);
|
||||||
|
|
||||||
let multi_line = self.input.read(cx).is_multi_line();
|
let multi_line = self.input.read(cx).is_multi_line();
|
||||||
|
|
@ -910,6 +912,7 @@ impl Element for TextElement {
|
||||||
|
|
||||||
// Paint text
|
// Paint text
|
||||||
let mut offset_y = mask_offset_y + invisible_top_padding;
|
let mut offset_y = mask_offset_y + invisible_top_padding;
|
||||||
|
|
||||||
for line in prepaint
|
for line in prepaint
|
||||||
.last_layout
|
.last_layout
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue