diff --git a/crates/ui-contract/src/contract/text.rs b/crates/ui-contract/src/contract/text.rs index c2743f2ecd..20ed0f31dc 100644 --- a/crates/ui-contract/src/contract/text.rs +++ b/crates/ui-contract/src/contract/text.rs @@ -620,8 +620,9 @@ fn arrive(ctx: &egui::Context, widget: egui::Id, decl: &TextPart, state: &mut Te state.select_on_click = true; return; } - // A multi-line field opens on its first line with nothing selected, so the text reads from its start. - if opened && !select_all && decl.options.multiline() { + // A multi-line field that asks for it (`open_at_start`) opens on its first line with nothing selected, so the text + // reads from its start. + if opened && !select_all && decl.options.open_at_start && decl.options.multiline() { adapter::select(ctx, widget, 0, 0); return; } diff --git a/crates/ui-contract/src/primitives/text_input.rs b/crates/ui-contract/src/primitives/text_input.rs index 2cdeec35ca..24a216e18f 100644 --- a/crates/ui-contract/src/primitives/text_input.rs +++ b/crates/ui-contract/src/primitives/text_input.rs @@ -115,6 +115,9 @@ pub struct TextOptions { /// A layer that opens on the field (`FocusOrigin::Open`) leaves the caret where the codec's rule puts it instead /// of selecting the whole text: a field that opens to add to its text (an edited comment) rather than replace it. pub keep_caret_on_open: bool, + /// A layer that opens on this multi-line field puts the caret at its start with nothing selected, so the text + /// reads from its first line (a form dialog's multi-line row). + pub open_at_start: bool, /// Selects the current text before this pass's typing, unless an IME composition is active. pub select_all: bool, /// Enter does something in the field itself (it saves or runs a search): the field takes the `Submit` intent, so the @@ -198,6 +201,7 @@ impl Default for TextOptions { steps_value: false, select_on_focus: false, keep_caret_on_open: false, + open_at_start: false, select_all: false, submits: false, mixed: false, diff --git a/crates/ui-patterns/src/patterns/form_dialogs/rows.rs b/crates/ui-patterns/src/patterns/form_dialogs/rows.rs index d444dd16a4..30349f7d3c 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/rows.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/rows.rs @@ -1560,7 +1560,7 @@ impl<'p> Pass<'p> { let mut field = TextField::new(line.name.clone(), line.bind(value.clone(), Some(default.to_owned()))).id_salt("text"); let options = line.param.option(); if let Some(lines) = options.lines() { - field = field.lines(lines); + field = field.lines(lines).open_at_start(); } if let Some(max) = options.max_chars() { field = field.limit(Some(max)); diff --git a/crates/ui-widgets/src/text/text_field.rs b/crates/ui-widgets/src/text/text_field.rs index 51baaee0b0..12f6a90ac2 100644 --- a/crates/ui-widgets/src/text/text_field.rs +++ b/crates/ui-widgets/src/text/text_field.rs @@ -211,6 +211,14 @@ impl<'a, C: Codec + Clone + 'static> TextField<'a, C> { self } + /// A layer that opens on this multi-line field puts its caret at the start with nothing selected, so the text + /// reads from its first line. Off by default: an opening layer selects the whole text. + #[must_use] + pub fn open_at_start(mut self) -> Self { + self.options.open_at_start = true; + self + } + /// With `on`, selects the whole text in this pass, so typing replaces it, unless the field is composing text; a /// request made during a composition is dropped. #[must_use]