Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Type: wire the Use Escape to Commit preference (#1927)

Reynold Hu429b9fc6a521
diff --git a/crates/engine/src/prefs.rs b/crates/engine/src/prefs.rs
index 8bf184767..ed4feae4c 100644
--- a/crates/engine/src/prefs.rs
+++ b/crates/engine/src/prefs.rs
@@ -867,7 +867,6 @@ pub const HIDDEN_UNTIL_IMPLEMENTED: &[&str] = &[
"type.smartQuotes",
"type.missingGlyphProtection",
"type.showFontNamesInEnglish",
- "type.useEscToCommit",
"type.textEngine",
"type.fontPreview",
"type.recentFonts",
diff --git a/crates/ui-egui/src/prefs_ui.rs b/crates/ui-egui/src/prefs_ui.rs
index c96c52552..2e6b2c6f1 100644
--- a/crates/ui-egui/src/prefs_ui.rs
+++ b/crates/ui-egui/src/prefs_ui.rs
@@ -1851,9 +1851,10 @@ mod tests {
for section in ["integrations", "scratchDisks"] {
assert!(!has_visible_fields(&values, section), "{section}");
}
- // "Fill new type layers with placeholder text" is live; other Type rows stay hidden.
+ // "Fill new type layers with placeholder text" and "Use Escape to Commit" are live; other Type rows stay hidden.
assert!(has_visible_fields(&values, "type"));
assert!(!prefs::is_hidden("type.fillNewTypeLayersWithPlaceholder"));
+ assert!(!prefs::is_hidden("type.useEscToCommit"));
assert!(prefs::is_hidden("type.smartQuotes"));
// Rotate View with Trackpad is live; the other Enhanced Controls rows stay hidden.
assert!(has_visible_fields(&values, "enhancedControls"));
diff --git a/crates/ui-egui/src/type_tool.rs b/crates/ui-egui/src/type_tool.rs
index 5dfc14abd..f595732e0 100644
--- a/crates/ui-egui/src/type_tool.rs
+++ b/crates/ui-egui/src/type_tool.rs
@@ -528,7 +528,10 @@ pub fn handle_keys(app: &mut PhotocraftApp, ctx: &egui::Context) -> bool {
Key::Enter if m.command => commit(app),
Key::Enter => insert(app, "\n"),
Key::Escape if crate::type_transform::active(app) => crate::type_transform::cancel_drag(app),
- Key::Escape => commit(app),
+ // Preferences ▸ Type: with "Use Escape to Commit" off, Escape cancels the
+ // session (undoes it, removing a just-created layer) like the Cancel button.
+ Key::Escape if app.session.prefs().type_.use_esc_to_commit => commit(app),
+ Key::Escape => cancel(app),
Key::A if m.command => {
if let Some(e) = app.ui.text_edit.as_mut() {
e.anchor = 0;
diff --git a/crates/ui-egui/src/type_tool_tests.rs b/crates/ui-egui/src/type_tool_tests.rs
index 1405a6854..fd3c4bb64 100644
--- a/crates/ui-egui/src/type_tool_tests.rs
+++ b/crates/ui-egui/src/type_tool_tests.rs
@@ -210,6 +210,26 @@ fn editing_psd_type_shows_our_layout_and_cancel_restores_it() {
assert_eq!(h.state().session.active().unwrap().history.entries().len(), steps);
}
+/// Preferences ▸ Type ▸ Use Escape to Commit (default on): with it off, Escape cancels the
+/// session like the Cancel button instead of committing.
+#[test]
+fn use_escape_to_commit_off_makes_escape_cancel_the_session() {
+ for (use_esc_to_commit, expected) in [(true, "HOxHOHO"), (false, "HOHOHO")] {
+ let mut app = new_app();
+ let id = LayerId(app.run("type.create", json!({"text": "HOHOHO", "size": 120, "x": 300, "y": 420})).unwrap()["layer"].as_u64().unwrap());
+ app.run("prefs.set", json!({"path": "type.useEscToCommit", "value": use_esc_to_commit})).unwrap();
+ let mut h = harness(1.0, app);
+ let p = glyph(&mut h, id, 2, 0.2);
+ click(&mut h, p);
+ super::insert(h.state_mut(), "x");
+ assert_eq!(text(h.state(), id).text, "HOxHOHO", "typing goes into the session");
+ h.key_press(egui::Key::Escape);
+ h.run_steps(2);
+ assert!(h.state().ui.text_edit.is_none(), "the session ends either way (useEscToCommit={use_esc_to_commit})");
+ assert_eq!(text(h.state(), id).text, expected, "useEscToCommit={use_esc_to_commit}");
+ }
+}
+
fn size_at(app: &PhotocraftApp, id: LayerId, ci: usize) -> f32 {
let t = text(app, id);
let b = t.text.char_indices().nth(ci).map_or(t.text.len(), |(b, _)| b);
diff --git a/docs/scorecard.md b/docs/scorecard.md
index c2bbd41ff..19ab073ab 100644
--- a/docs/scorecard.md
+++ b/docs/scorecard.md
@@ -9,7 +9,7 @@ Generated by `cargo xtask scorecard` from `perf/budgets.toml`, `perf/baseline.js
| [Performance](#performance) | 3 | 22 | 14 | 48 scenarios: 3 within budget, 22 over budget or failing, 9 tracked only, 7 not run, 7 not measurable yet (baseline 2026-10-05) |
| [File compatibility](#file-compatibility) | 4 | 12 | 11 | io corpus: oracle ≥ 146/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 236/309, round trip ≥ 307/309; photoshop oracles: oracle ≥ 133/256, round trip ≥ 258/256 |
| [Tools](#tools) | 13 | 14 | 8 | |
-| [Workspace and UI](#workspace-and-ui) | 5 | 6 | 12 | settings that do nothing: 53 of 141 (target 0) |
+| [Workspace and UI](#workspace-and-ui) | 5 | 6 | 12 | settings that do nothing: 52 of 141 (target 0) |
| [Type](#type) | 0 | 3 | 6 | |
| [Automation](#automation) | 3 | 2 | 6 | 627 of 627 menu items live (100.0%) |
| [Reliability](#reliability) | 5 | 0 | 2 | never-crash lints on 28 of 28 crates; panic_hunt present |
@@ -160,9 +160,9 @@ Corpus floors (`crates/io/tests/corpus.rs`): the enforced minimums; the corpus t
## Workspace and UI
-**Settings that do nothing: 53 of 141** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't.
+**Settings that do nothing: 52 of 141** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't.
-Unread: `general.color_picker`, `general.beep_when_done`, `general.export_clipboard`, `general.resize_image_during_place`, `general.always_create_smart_objects_when_placing`, `general.animated_zoom`, `general.zoom_resizes_windows`, `interface.show_channels_in_color`, `interface.dynamic_color_sliders`, `workspace.auto_collapse_icon_panels`, `workspace.auto_show_hidden_panels`, `workspace.open_documents_as_tabs`, `workspace.enable_floating_document_window_docking`, `workspace.large_tabs`, `workspace.enable_narrow_options_bar`, `tools.enable_flick_panning`, `tools.vary_round_brush_hardness_on_hud`, `tools.show_transformation_values`, `tools.double_click_layer_mask_launches_select_and_mask`, `file_handling.image_previews`, `file_handling.lowercase_extension`, `file_handling.save_in_background`, `file_handling.ignore_exif_profile_tag`, `file_handling.maximize_psd_compatibility`, `performance.cache_levels`, `performance.legacy_compositing`, `scratch_disks.disks`, `cursors.brush_preview_color`, `units_and_rulers.type_units`, `units_and_rulers.column_width`, `units_and_rulers.gutter`, `units_and_rulers.print_resolution`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `plug_ins.generator_enabled`, `type_.smart_quotes`, `type_.missing_glyph_protection`, `type_.show_font_names_in_english`, `type_.use_esc_to_commit`, `type_.text_engine`, `type_.font_preview`, `type_.recent_fonts`, `enhanced_controls.scrubby_slider_acceleration`, `enhanced_controls.touch_gestures`, `enhanced_controls.zoom_with_trackpad_pinch`, `raw_defaults.color_space`, `raw_defaults.bit_depth`, `raw_defaults.resolution`, `raw_defaults.sharpen_for`, `raw_defaults.open_as_smart_object`, `raw_defaults.apply_auto_tone`, `integrations.allow_agent_control`, `integrations.control_port`.
+Unread: `general.color_picker`, `general.beep_when_done`, `general.export_clipboard`, `general.resize_image_during_place`, `general.always_create_smart_objects_when_placing`, `general.animated_zoom`, `general.zoom_resizes_windows`, `interface.show_channels_in_color`, `interface.dynamic_color_sliders`, `workspace.auto_collapse_icon_panels`, `workspace.auto_show_hidden_panels`, `workspace.open_documents_as_tabs`, `workspace.enable_floating_document_window_docking`, `workspace.large_tabs`, `workspace.enable_narrow_options_bar`, `tools.enable_flick_panning`, `tools.vary_round_brush_hardness_on_hud`, `tools.show_transformation_values`, `tools.double_click_layer_mask_launches_select_and_mask`, `file_handling.image_previews`, `file_handling.lowercase_extension`, `file_handling.save_in_background`, `file_handling.ignore_exif_profile_tag`, `file_handling.maximize_psd_compatibility`, `performance.cache_levels`, `performance.legacy_compositing`, `scratch_disks.disks`, `cursors.brush_preview_color`, `units_and_rulers.type_units`, `units_and_rulers.column_width`, `units_and_rulers.gutter`, `units_and_rulers.print_resolution`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `plug_ins.generator_enabled`, `type_.smart_quotes`, `type_.missing_glyph_protection`, `type_.show_font_names_in_english`, `type_.text_engine`, `type_.font_preview`, `type_.recent_fonts`, `enhanced_controls.scrubby_slider_acceleration`, `enhanced_controls.touch_gestures`, `enhanced_controls.zoom_with_trackpad_pinch`, `raw_defaults.color_space`, `raw_defaults.bit_depth`, `raw_defaults.resolution`, `raw_defaults.sharpen_for`, `raw_defaults.open_as_smart_object`, `raw_defaults.apply_auto_tone`, `integrations.allow_agent_control`, `integrations.control_port`.
| Id | Target | Status | Issue | Note |
|---|---|---|---|---|