From 8b0898147ff3ff92957165beacc454d76811f5f3 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Tue, 30 Sep 2025 16:07:03 +0800 Subject: [PATCH] editor: Fix Editor crash when text is empty to display placeholder. (#1314) --- crates/ui/src/input/element.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/ui/src/input/element.rs b/crates/ui/src/input/element.rs index 61131bfd..800a2338 100644 --- a/crates/ui/src/input/element.rs +++ b/crates/ui/src/input/element.rs @@ -537,6 +537,7 @@ impl TextElement { window: &mut Window, ) -> Vec { 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(), @@ -548,6 +549,23 @@ impl TextElement { return vec![LineLayout::new().lines(smallvec::smallvec![shaped_line])]; } + // Empty to use placeholder, the placeholder is not in the text_wrapper map. + if state.text.len() == 0 { + return display_text + .to_string() + .split("\n") + .map(|line| { + let shaped_line = window.text_system().shape_line( + line.to_string().into(), + font_size, + &runs, + None, + ); + LineLayout::new().lines(smallvec::smallvec![shaped_line]) + }) + .collect(); + } + let visible_text = display_text .slice_lines(visible_range.start..visible_range.end) .to_string();