editor: Fix Editor crash when text is empty to display placeholder. (#1314)

This commit is contained in:
Jason Lee 2025-09-30 16:07:03 +08:00 committed by GitHub
parent 591cfc8dab
commit 8b0898147f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -537,6 +537,7 @@ impl TextElement {
window: &mut Window,
) -> Vec<LineLayout> {
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();