From 52b58c05191591fdafa505f95e2bb0204e2374b5 Mon Sep 17 00:00:00 2001 From: aiongg Date: Mon, 12 Oct 2026 04:01:12 +0000 Subject: [PATCH] Text: Bold and Italic that change nothing add no undo step --- crates/engine/src/cmd/text.rs | 9 +++++++++ 1 file changed, 9 insertions(+) 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 { }); } } + // 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();