From 3a6741f990d6f0fdb47042a48011b215968b7f0d Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Mon, 23 Jun 2025 18:14:29 +0800 Subject: [PATCH] input: Fix wrap text not draw in multi-line mode. (#998) Close #997 https://github.com/user-attachments/assets/6ad9f431-b5a2-42f1-93e6-6425f0851898 --- crates/ui/src/input/element.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/ui/src/input/element.rs b/crates/ui/src/input/element.rs index 5f9ac6b3..5c4dc52c 100644 --- a/crates/ui/src/input/element.rs +++ b/crates/ui/src/input/element.rs @@ -333,14 +333,15 @@ impl TextElement { &self, state: &InputState, line_height: Pixels, - bounds: &Bounds, + input_height: Pixels, ) -> Range { if state.is_single_line() { return 0..1; } 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.); for (ix, line) in state.text_wrapper.lines.iter().enumerate() { line_top += line.height(line_height); @@ -348,8 +349,9 @@ impl TextElement { if line_top < scroll_top { 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; } } @@ -536,7 +538,7 @@ impl Element for TextElement { let state = self.input.read(cx); 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 multi_line = self.input.read(cx).is_multi_line(); @@ -910,6 +912,7 @@ impl Element for TextElement { // Paint text let mut offset_y = mask_offset_y + invisible_top_padding; + for line in prepaint .last_layout .iter()