diff --git a/core/src/text/paragraph.rs b/core/src/text/paragraph.rs index 700c2c7595..5cf3a28533 100644 --- a/core/src/text/paragraph.rs +++ b/core/src/text/paragraph.rs @@ -139,4 +139,9 @@ impl Plain

{ pub fn raw(&self) -> &P { &self.raw } + + /// Returns the content of the [`Paragraph`]. + pub fn content(&self) -> &str { + self.content.as_str() + } } diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs index 215ecbd6a3..c5368304f7 100644 --- a/widget/src/text_input.rs +++ b/widget/src/text_input.rs @@ -420,7 +420,11 @@ where cursor::State::Selection { start, end } => start.min(end), }; - let text = state.value.raw(); + let text = if state.value.content().is_empty() { + state.placeholder.raw() + } else { + state.value.raw() + }; let (cursor_x, scroll_offset) = measure_cursor_and_scroll_offset(text, text_bounds, caret_index);