New Guide Layout (#6083): tabbing past a field keeps the preset

Leaving a length field without typing rewrote its value on focus loss: an
empty automatic Width turned from null into "", which made a named preset
such as "8 Columns" switch to Custom. The field now writes back only when
normalising changes the text shown.

Co-Authored-By: safvanedge <safvanedge@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
committed 2026-11-08 01:49:24 +01:00
1 parent c9204e7c45
commit 22ddcd3f7d
2 files changed
+30 -1

No files matched your search

@@ -426,7 +426,11 @@ fn unit_edit(app: &PhotocraftApp, ui: &mut egui::Ui, id_salt: &str, value: &mut
}
if response.lost_focus() {
let unit = ui.ctx().data_mut(|d| d.remove_temp::<Unit>(response.id)).unwrap_or(ruler);
if let Some(normalized) = normalize_field_text(&text, app, along_x, optional, unit) {
// Leaving a field untouched keeps its stored value (an automatic size stays empty), so
// tabbing past it does not turn a named preset into Custom.
if let Some(normalized) = normalize_field_text(&text, app, along_x, optional, unit)
&& normalized != text
{
*value = json!(normalized);
}
}
@@ -408,3 +408,28 @@ fn a_bare_number_takes_the_unit_the_field_showed() {
h.run_steps(2);
assert_eq!(h.state().ui.dialogs.first().unwrap().fields["gutter"], "5 mm");
}
/// Tabbing past fields without typing keeps a named preset: an empty Width stays automatic.
#[test]
fn tabbing_through_untouched_fields_keeps_the_preset() {
let mut app = app();
let id = open(&mut app);
let f = &mut app.ui.dialog_mut(id).unwrap().fields;
f.insert("__preset".into(), json!("eight"));
f.insert("columns".into(), json!(8));
f.insert("rows".into(), json!(0));
f.insert("__rowsEnabled".into(), json!(false));
f.insert("__marginEnabled".into(), json!(false));
f.insert("width".into(), Value::Null);
f.insert("gutter".into(), json!(20));
let mut h = harness(app);
h.run_steps(3);
// Number, Width, Spacing, then back to Number.
for _ in 0..4 {
h.key_press(egui::Key::Tab);
h.run_steps(2);
}
let f = &h.state().ui.dialogs.first().unwrap().fields;
assert_eq!(f["__preset"], "eight");
assert_eq!(f["width"], Value::Null);
}