Skip to content

Commit

Permalink
Fix position of preedit doesn't consider placeholder in TextInput
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Feb 4, 2025
1 parent 782b96b commit 23ed2b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions core/src/text/paragraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,9 @@ impl<P: Paragraph> Plain<P> {
pub fn raw(&self) -> &P {
&self.raw
}

/// Returns the content of the [`Paragraph`].
pub fn content(&self) -> &str {
self.content.as_str()
}
}
6 changes: 5 additions & 1 deletion widget/src/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 23ed2b6

Please sign in to comment.