Skip to content

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

Text: Bold and Italic that change nothing add no undo step

aiongg52b58c051915
diff --git a/crates/engine/src/cmd/text.rs b/crates/engine/src/cmd/text.rs
index 46ef34f94..de48e4884 100644
--- a/crates/engine/src/cmd/text.rs
+++ b/crates/engine/src/cmd/text.rs
@@ -1168,6 +1168,10 @@ fn link_style(s: &mut Session, p: &Value, bold: bool) -> Result<Value> {
});
}
}
+ // No undo step for nothing.
+ if changed == 0 {
+ return Err(bad(id, "nothing to change"));
+ }
ok()
});
r?;
@@ -1586,6 +1590,11 @@ mod style_link_tests {
s.execute("type.bold", &json!({})).unwrap();
assert_eq!(style_at(&mut s, 0), "Italic");
assert_eq!(style_at(&mut s, 7), "Regular");
+ // Nothing to change: an error and no undo step.
+ s.execute("text.select", &json!({"story": sid, "anchor": 6, "focus": 11})).unwrap();
+ let steps = s.doc().unwrap().history.undo.len();
+ assert!(s.execute("type.bold", &json!({"on": false})).is_err());
+ assert_eq!(s.doc().unwrap().history.undo.len(), steps);
// At a caret the style is for what is typed next.
let end = "plain words here".len();
s.execute("text.select", &json!({"story": sid, "anchor": end, "focus": end})).unwrap();