mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-15 06:53:35 +00:00
Gap 19: a kept ODT form control made another kind saves as that kind
Review fix. A button kept verbatim was still written as the button after its content control was made another kind (a check box, a list). The kept form XML is now used only while the control is still the plain text control it was read as. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GBVQLyDnrG8Tn1yDQcUabC
This commit is contained in:
2 files changed
+17
-2
No files matched your search
@@ -242,8 +242,9 @@ pub(in crate::odt) fn form_xml(c: &ContentControl, text: &str, id: &str, n: usiz
|
||||
None => (xml, w, h),
|
||||
}
|
||||
};
|
||||
// A control kept verbatim, with its new id.
|
||||
if !c.form_xml.is_empty() {
|
||||
// A control kept verbatim, with its new id, while it is still the control it was read as
|
||||
// (made another kind, it is written as that).
|
||||
if !c.form_xml.is_empty() && c.kind == (ControlKind::Text { multi_line: false }) {
|
||||
let end = c.form_xml.find(|ch: char| ch.is_whitespace() || ch == '>')?;
|
||||
let (head, rest) = (c.form_xml.get(..end)?, c.form_xml.get(end..)?);
|
||||
return Some(size((format!("{head} xml:id=\"{id}\" form:id=\"{id}\"{rest}"), 72.0, 20.0)));
|
||||
|
||||
@@ -130,6 +130,20 @@ fn buttons_are_kept() {
|
||||
"{c}"
|
||||
);
|
||||
assert!(c.contains(r#"svg:width="72pt" svg:height="21.6pt" draw:control="control1""#), "{c}");
|
||||
// Made a check box, it is saved as one.
|
||||
let mut c = wordcraft_doc::control::ContentControl::new(ControlKind::Text { multi_line: false });
|
||||
c.form_xml = "<form:button form:name=\"Go\"></form:button>".into();
|
||||
let kept = crate::odt::forms::form_xml(&c, "Go", "control1", 1).unwrap().0;
|
||||
assert!(kept.starts_with(r#"<form:button xml:id="control1" form:id="control1" form:name="Go">"#), "{kept}");
|
||||
c.kind = ControlKind::CheckBox {
|
||||
checked: true,
|
||||
checked_char: '\u{2612}',
|
||||
checked_font: String::new(),
|
||||
unchecked_char: '\u{2610}',
|
||||
unchecked_font: String::new(),
|
||||
};
|
||||
let made = crate::odt::forms::form_xml(&c, "\u{2612}", "control1", 1).unwrap().0;
|
||||
assert!(made.starts_with("<form:checkbox "), "{made}");
|
||||
// And again: still a button.
|
||||
let again = entry(&export(&import(&saved).unwrap()).unwrap(), "content.xml");
|
||||
assert_eq!(again.matches("<form:button ").count(), 1, "{again}");
|
||||
|
||||
Reference in new issue
Block a user