Check Spelling: Enter is Done, also from Change To

Done is the dialog's default button, as in the reference application: Enter runs it from Change To
(without changing the word) and with nothing focused; a focused button keeps its own Enter and the
suggestions list keeps Enter as Change. Escape stays Done. Ported from storytold/photocraft#14328
by TrevorBrown-dev.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David MannandClaude Opus 5.5 committed 2026-11-29 20:33:55 +01:00
1 parent 91d41e8ce5
commit 463af6d258
2 files changed
+57 -6

No files matched your search

+5 -4
View File
@@ -179,9 +179,10 @@ impl Outcome for SpellingOutput {
/// "Spell check complete." once the list is empty; at the right, a column of Done and the buttons Ignore, Ignore All,
/// Change, Change All and Add, which are disabled when the list is empty.
///
/// - A click on a suggestion puts it in Change To; a double click or Enter also changes.
/// - Enter is Done unless Change To has focus; Escape and the close action are Done too (nothing to undo: every
/// change was made as it was asked for). Tab walks Change To, the suggestions (one stop, arrows inside), the check
/// - A click on a suggestion puts it in Change To; a double click or Enter on the list also changes.
/// - Done is the default button: Enter runs it, also from Change To (where it does not change the word), and a
/// focused button keeps its own Enter. Escape and the close action are Done too (nothing to undo: every change was
/// made as it was asked for). Tab walks Change To, the suggestions (one stop, arrows inside), the check
/// box and the buttons.
/// - Result: `()`; every close from inside (Done, Escape, the close action, automation's confirm) is
/// [`DialogResult::Ok`], and a close from outside is `Cancel`.
@@ -276,7 +277,7 @@ impl CheckSpellingDialog {
];
let buttons = std::iter::once(FooterButton::new(words.done.clone(), DialogRole::Accept))
.chain(actions.iter().map(|(label, _)| FooterButton::new((*label).clone(), DialogRole::Other).stays_open(true).enabled(has_item)));
let dialog = Dialog::new(words.title.clone()).button_place(ButtonPlace::Side).buttons(buttons).opened(Bind::bound(open));
let dialog = Dialog::new(words.title.clone()).button_place(ButtonPlace::Side).buttons(buttons).close_on_enter(true).opened(Bind::bound(open));
let shown = dialog.show(ui, |ui, _| {
let word = item.as_ref().map_or_else(String::new, |i| i.word.clone());
Field::new(words.not_in_dictionary.clone()).id_salt("word").show(ui, |ui, _| {
+52 -2
View File
@@ -1,12 +1,13 @@
//! Check Spelling's Ignore and restart.
//! Check Spelling's Ignore and restart, and its keys: Enter and Escape are Done (#14179 in storytold/photocraft).
use std::cell::RefCell;
use std::cell::{Cell, RefCell};
use std::rc::Rc;
use craft_text::ui::spelling::{CheckSpellingDialog, SpellingAction, SpellingItem};
use craft_ui::contract::Role;
use craft_ui::dialog::StackDialog as _;
use craft_ui::testing::{Fixture, trial};
use egui::{Key, Modifiers};
use serde_json::json;
fn items() -> Vec<SpellingItem> {
@@ -56,3 +57,52 @@ fn restarting_drops_a_change_waiting_on_the_previous_word() {
fixture.click(&change).settle();
assert_eq!(dialog.borrow_mut().take_action(), Some(SpellingAction::Change { item: next, to: "and".to_owned() }));
}
/// A fixture showing the dialog, with whether it has closed.
fn shown() -> (Fixture, Rc<RefCell<CheckSpellingDialog>>, Rc<Cell<bool>>) {
let dialog = Rc::new(RefCell::new(CheckSpellingDialog::new(items())));
let closed = Rc::new(Cell::new(false));
let (shown, ended) = (dialog.clone(), closed.clone());
let mut fixture = Fixture::new(move |ui| {
if shown.borrow_mut().show(ui).closed.is_some() {
ended.set(true);
}
});
fixture.settle();
(fixture, dialog, closed)
}
/// Focuses Change To and types into it, so the keys after go to the field.
fn type_in_change_to(fixture: &mut Fixture, dialog: &Rc<RefCell<CheckSpellingDialog>>) {
let field = fixture.by_label("Change To:").expect("the Change To field");
fixture.click(&field).settle();
fixture.type_text("x").settle();
assert_eq!(dialog.borrow().json_fields().expect("fields")["changeTo"], json!("thex"), "Change To has the focus");
}
// Done is the default button: Enter in Change To closes the dialog and does not change the word.
#[trial]
fn enter_in_change_to_is_done_and_changes_nothing() {
let (mut fixture, dialog, closed) = shown();
type_in_change_to(&mut fixture, &dialog);
fixture.key(Key::Enter, Modifiers::NONE).settle();
assert!(closed.get(), "Enter in Change To closes the dialog");
assert_eq!(dialog.borrow_mut().take_action(), None, "and does not change the word");
}
#[trial]
fn enter_with_nothing_focused_is_done() {
let (mut fixture, dialog, closed) = shown();
fixture.key(Key::Enter, Modifiers::NONE).settle();
assert!(closed.get(), "Enter closes the dialog");
assert_eq!(dialog.borrow_mut().take_action(), None, "as Done, with no action");
}
#[trial]
fn escape_in_change_to_is_done() {
let (mut fixture, dialog, closed) = shown();
type_in_change_to(&mut fixture, &dialog);
fixture.key(Key::Escape, Modifiers::NONE).settle();
assert!(closed.get(), "Escape in Change To closes the dialog");
assert_eq!(dialog.borrow_mut().take_action(), None, "with no action");
}