From 80807123fb9fdb20fab5f3b08200ee150399ba3b Mon Sep 17 00:00:00 2001 From: David Mann Date: Fri, 20 Nov 2026 20:14:04 +0100 Subject: [PATCH] Color Picker: Enter in the Full layout's hex field confirms 3155a1d38 made the hex field own Enter for the tabbed Colors dialog. The Full layout focuses the same field on its first show, so its Enter only committed the digits and the dialog stayed open. In the reference image editor's Color Picker, digits typed there and Enter set the colour and close the dialog. The field owns Enter in the Compact layout only. --- crates/color-ui/src/ui/picker/compact.rs | 12 ++++++----- crates/color-ui/tests/it/picker.rs | 26 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/crates/color-ui/src/ui/picker/compact.rs b/crates/color-ui/src/ui/picker/compact.rs index b582f2aa9..ec93908f3 100644 --- a/crates/color-ui/src/ui/picker/compact.rs +++ b/crates/color-ui/src/ui/picker/compact.rs @@ -127,12 +127,14 @@ impl<'a> Body<'a> { } } - /// The hex field, at `sizing` when given. The picker's first show focuses it, its text selected. Enter in it - /// commits the typed digits and does not reach the dialog's OK, as in the production Colors dialog. + /// The hex field, at `sizing` when given. The picker's first show focuses it, its text selected. In the Compact + /// layout (the tabbed Colors dialog) Enter in it commits the typed digits and does not reach the dialog's OK, as in + /// the production Colors dialog. In the Full layout Enter commits the digits and confirms the dialog, as in the + /// reference image editor's Color Picker. pub(super) fn hex_field(&self, ui: &mut Ui, pass: &Pass<'a>, words: &ColorPickerWords, sizing: Option, got: &mut Collected) { - let field = TextField::hex(words.hex.as_str().to_owned(), Bind::given(pass.shows(pass.shown.color.to_rgba()))) - .empty(pass.shown.color.to_rgba()) - .submits(); + let field = + TextField::hex(words.hex.as_str().to_owned(), Bind::given(pass.shows(pass.shown.color.to_rgba()))).empty(pass.shown.color.to_rgba()); + let field = if self.layout == ColorPickerLayout::Compact { field.submits() } else { field }; let edit = match sizing { Some(sizing) => field.sizing(sizing), None => field, diff --git a/crates/color-ui/tests/it/picker.rs b/crates/color-ui/tests/it/picker.rs index 029e9fe7d..cafcc67d9 100644 --- a/crates/color-ui/tests/it/picker.rs +++ b/crates/color-ui/tests/it/picker.rs @@ -450,3 +450,29 @@ fn the_tabbed_colors_dialog_opens_on_its_tab_and_answers_from_either_page() { let answered = dialogs.borrow_mut().take::().and_then(DialogResult::ok).map(|result| result.picked.color.to_hex()); assert_eq!(answered.as_deref(), Some("#0000ff")); } + +/// The Full dialog opens with its hex field focused and selected; digits typed there and Enter commit the colour and +/// confirm the dialog, as in the reference image editor's Color Picker (the tabbed Colors dialog keeps Enter in the +/// field instead). +#[trial] +fn enter_in_the_full_dialogs_hex_field_confirms_the_typed_colour() { + let dialogs = Rc::new(RefCell::new(DialogHost::new())); + let shown = Rc::clone(&dialogs); + let mut fixture = Fixture::new(move |ui| shown.borrow_mut().run(ui)); + fixture.room(vec2(900.0, 700.0)); + fixture.host(std::sync::Arc::new(Host::builder(AppInfo { id: "picker-test", name: "Picker test", version: "0" }).build())); + let colour = |hex: &str| Srgba::from_hex(hex).expect("a colour"); + dialogs + .borrow_mut() + .open(ColorPickerDialog::new("foreground", "Color Picker (Foreground Color)", colour("#000000")).web_colors_remembered(false)); + fixture.idle(6); + assert!(dialogs.borrow().get::().is_some(), "the picker is open"); + + fixture.type_text("336699"); + fixture.key(Key::Enter, Modifiers::NONE); + fixture.settle(); + assert!(dialogs.borrow().get::().is_none(), "Enter in the hex field confirms the dialog"); + let answer = dialogs.borrow_mut().take::(); + let Some(DialogResult::Ok(result)) = answer else { panic!("the dialog answers OK") }; + assert_eq!(result.picked.color.to_hex(), "#336699", "with the typed colour"); +}