Skip to content

text input: EditableText::value() -> Cow<str> - #25532

Open
Cyannide wants to merge 1 commit into
bevyengine:mainfrom
Cyannide:editable_text_value_cow
Open

text input: EditableText::value() -> Cow<str>#25532
Cyannide wants to merge 1 commit into
bevyengine:mainfrom
Cyannide:editable_text_value_cow

Conversation

@Cyannide

Copy link
Copy Markdown
Contributor

Objective

Split out of #25117 as a standalone PR by reviewer suggestion to benefit other parley edit consumers.

Previously EditableText::value() returned a parley SplitString, which required every consumer to reassemble the segments by hand for just about any use case.

Solution

By returning a Cow<str> (usually borrowed) most existing code continues working unchanged using deref, IME being an owned exception because of the preedit split during composition.

Testing

FeathersNumberInput and the multiline/multiple-input examples converted to the new API (manual reassembly now one liners) run and exercised. Also tested with several call sites in a 0.19 backport for a production WASM and desktop app exercised by 1-8 grade students on their login screen every morning.

Migration

Guide included, existing call sites adopted in the PR.

Previously value() returned a parley SplitString, which required every
consumer to reassemble the segments by hand for just about any use case.
With Cow<str> (usually borrowed) most existing code continues working
unchanged using deref, IME being an owned exception because of the preedit
split during composition.

FeathersNumberInput and the multiline/multiple-input examples converted
to the new API with manual reassembly now one liners.
@Cyannide
Cyannide force-pushed the editable_text_value_cow branch from d95bb48 to 4b2fa71 Compare August 24, 2026 03:04
Cyannide added a commit to Cyannide/bevy that referenced this pull request Aug 24, 2026
Rebased onto the value() -> Cow split (bevyengine#25532)

The display buffer holds mask glyphs while the entered text lives in
EditableText::shadow_value, and value() reads through the shadow into
the entered text so the mask only affects the display. Paste routes
through masked_insert so the clipboard string never exists in the
visible buffer.

Migration guide now in the Cow return PR.
Cyannide added a commit to Cyannide/bevy that referenced this pull request Aug 24, 2026
Rebased onto the value() -> Cow split (bevyengine#25532)

The display buffer holds mask glyphs while the entered text lives in
EditableText::shadow_value, and value() reads through the shadow into
the entered text so the mask only affects the display. Paste routes
through masked_insert so the clipboard string never exists in the
visible buffer.

value() migration guide now part of the Cow return PR, the
apply_pending_edits() guide still here.
pub fn value(&self) -> SplitString<'_> {
self.editor.text()
/// Borrowed as default, owned copy returned when there is a split
/// (e.g. IME preedit).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain the logic here, why is there first and second?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally second is empty, but when an IME preedit is active, parley returns two segments, the part before and the part after the preedit. So the owned version combines the two.

@Zeophlite Zeophlite added A-UI Graphical user interfaces, styles, layouts, and widgets D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 24, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in UI Aug 24, 2026
@Zeophlite
Zeophlite requested a review from ickshonpe August 24, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-UI Graphical user interfaces, styles, layouts, and widgets D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

2 participants