Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Typing the automatic leading over its value fixes it

moppeeeraa3b7b7a2416
diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs
index e84376584..cd937bc47 100644
--- a/crates/ui-egui/src/chrome.rs
+++ b/crates/ui-egui/src/chrome.rs
@@ -1370,6 +1370,19 @@ mod tests {
press(&mut h, pos2(size.min.x - 5.0 - crate::widgets::SEG_W / 2.0, size.min.y + 3.0));
h.run_steps(3);
assert_eq!(size_of(&h), Some(73.0));
+ // Typing the automatic value itself over "(87.6 pt)" fixes the leading at it.
+ h.state_mut().app.run("type.char", serde_json::json!({"attrs": {"leading": {"kind": "auto"}}})).unwrap();
+ h.run_steps(3);
+ let lead = field(&h, "(87.6 pt)");
+ press(&mut h, lead.center());
+ h.run_steps(2);
+ h.event(egui::Event::Key { key: egui::Key::A, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::COMMAND });
+ h.event(egui::Event::Text("87.6".into()));
+ h.key_press(egui::Key::Enter);
+ h.run_steps(3);
+ let st = h.state().app.session.doc().unwrap();
+ let sid = designcraft_doc::StoryId(f["story"].as_u64().unwrap());
+ assert_eq!(st.doc.story(sid).unwrap().format_after(0).over.leading, Some(designcraft_doc::Leading::Points(87.6)));
}
#[test]
diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs
index fb9876aa2..0d6596114 100644
--- a/crates/ui-egui/src/widgets.rs
+++ b/crates/ui-egui/src/widgets.rs
@@ -227,8 +227,11 @@ impl<'a> NumField<'a> {
ui.data_mut(|d| d.insert_temp(key, buf.clone()));
}
if r.lost_focus() {
+ // An automatic value (in parentheses) typed over commits even when it's the same
+ // number: typing "14.4 pt" over "(14.4 pt)" makes it a fixed value.
+ let typed_over_auto = self.parens && !buf.trim_start().starts_with('(');
if let Some(v) = self.parse(&buf).map(clamp)
- && self.value.is_none_or(|old| (old - v).abs() > 1e-9)
+ && (typed_over_auto || self.value.is_none_or(|old| (old - v).abs() > 1e-9))
{
out = Some(v);
} else if buf.trim().is_empty() && self.value.is_some() {