From b42a429fdcb6edd2baba67d96f701c9005e489c8 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Thu, 23 Oct 2025 16:03:38 +0800 Subject: [PATCH] input: Fix Input to prepare text wrapper. (#1417) To ensure call update_all in TextWrapper. --- crates/ui/src/input/text_input.rs | 1 + crates/ui/src/input/text_wrapper.rs | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/crates/ui/src/input/text_input.rs b/crates/ui/src/input/text_input.rs index e06371b1..3641da1c 100644 --- a/crates/ui/src/input/text_input.rs +++ b/crates/ui/src/input/text_input.rs @@ -247,6 +247,7 @@ impl RenderOnce for TextInput { self.state.update(cx, |state, cx| { state.text_wrapper.set_font(font, font_size, cx); + state.text_wrapper.prepare_if_need(&state.text, cx); state.disabled = self.disabled; }); diff --git a/crates/ui/src/input/text_wrapper.rs b/crates/ui/src/input/text_wrapper.rs index 6149e3c7..ae7d9ccb 100644 --- a/crates/ui/src/input/text_wrapper.rs +++ b/crates/ui/src/input/text_wrapper.rs @@ -59,6 +59,8 @@ pub(super) struct TextWrapper { pub(super) longest_row: LongestRow, /// The lines by split \n pub(super) lines: Vec, + + _initialized: bool, } #[allow(unused)] @@ -72,6 +74,7 @@ impl TextWrapper { soft_lines: 0, longest_row: LongestRow::default(), lines: Vec::new(), + _initialized: false, } } @@ -111,6 +114,14 @@ impl TextWrapper { self.update_all(&self.text.clone(), cx); } + pub(super) fn prepare_if_need(&mut self, text: &Rope, cx: &mut App) { + if self._initialized { + return; + } + self._initialized = true; + self.update_all(text, cx); + } + /// Update the text wrapper and recalculate the wrapped lines. /// /// If the `text` is the same as the current text, do nothing.