From 3ee8d7ffd271efd139d510a298155e3d7f8dbcdb Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Mon, 29 Sep 2025 10:40:39 +0800 Subject: [PATCH] input: Fix input mark text render. (#1298) Fix #1293 change broken the input mask render (password mask, placeholder ...) --- crates/ui/src/input/element.rs | 21 ++++++++++++++++++--- crates/ui/src/input/text_wrapper.rs | 5 +++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/crates/ui/src/input/element.rs b/crates/ui/src/input/element.rs index 333c1d80..ab0632e8 100644 --- a/crates/ui/src/input/element.rs +++ b/crates/ui/src/input/element.rs @@ -527,14 +527,27 @@ impl TextElement { } fn layout_lines( - text: &Rope, + state: &InputState, + display_text: &Rope, text_wrapper: &TextWrapper, visible_range: &Range, font_size: Pixels, runs: &[TextRun], window: &mut Window, ) -> Vec { - let visible_text = text + let is_multi_line = state.mode.is_multi_line(); + if !is_multi_line { + let shaped_line = window.text_system().shape_line( + display_text.to_string().into(), + font_size, + &runs, + None, + ); + + return vec![LineLayout::new().lines(smallvec::smallvec![shaped_line])]; + } + + let visible_text = display_text .slice_lines(visible_range.start..visible_range.end) .to_string(); @@ -545,6 +558,7 @@ impl TextElement { .lines .get(visible_range.start + ix) .expect("line should exists in text_wrapper"); + // if line_item.len() != line.len() { // dbg!(&line, &line_item.wrapped_lines); // } @@ -853,7 +867,8 @@ impl Element for TextElement { }; let lines = Self::layout_lines( - &text, + &state, + &display_text, &state.text_wrapper, &visible_range, font_size, diff --git a/crates/ui/src/input/text_wrapper.rs b/crates/ui/src/input/text_wrapper.rs index 49686874..164d43d2 100644 --- a/crates/ui/src/input/text_wrapper.rs +++ b/crates/ui/src/input/text_wrapper.rs @@ -255,6 +255,11 @@ impl LineLayout { } } + pub(crate) fn lines(mut self, wrapped_lines: SmallVec<[ShapedLine; 1]>) -> Self { + self.set_wrapped_lines(wrapped_lines); + self + } + pub(crate) fn set_wrapped_lines(&mut self, wrapped_lines: SmallVec<[ShapedLine; 1]>) { self.len = wrapped_lines.iter().map(|l| l.len).sum(); let width = wrapped_lines