From 23ed2b649274ac5aa53a7fd74ad04bf726c569ed Mon Sep 17 00:00:00 2001 From: rhysd Date: Tue, 4 Feb 2025 19:48:36 +0900 Subject: [PATCH] Fix position of preedit doesn't consider placeholder in `TextInput` --- core/src/text/paragraph.rs | 5 +++++ widget/src/text_input.rs | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) 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);