DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Word import: keep tracked moved text (w:moveTo) (#257)
thaynej4aea57fea7f1
diff --git a/contributors/people.toml b/contributors/people.tomlindex 89c6db208..c480bd68a 100644--- a/contributors/people.toml+++ b/contributors/people.toml@@ -21,3 +21,6 @@real_name = "Brandon Thomas"display_name = "Brandon Thomas"sync_github_name = false++[people.thaynej]+real_name = "Jeffrey Thayne"diff --git a/crates/textimport/src/docx.rs b/crates/textimport/src/docx.rsindex 563eb7289..670f8a0fa 100644--- a/crates/textimport/src/docx.rs+++ b/crates/textimport/src/docx.rs@@ -276,7 +276,9 @@ impl Ctx {for e in p.els() {match e.name.as_str() {"r" => self.run(e, st, allow_notes),- "hyperlink" | "smartTag" | "ins" | "fldSimple" | "customXml" => self.inline(e, st, allow_notes),+ // Tracked changes import as accepted: insertions and move destinations are kept,+ // deletions (`del`) and move sources (`moveFrom`) are dropped.+ "hyperlink" | "smartTag" | "ins" | "moveTo" | "fldSimple" | "customXml" => self.inline(e, st, allow_notes),_ => {}}}@@ -469,4 +471,23 @@ mod tests {assert_eq!(i.para_styles[0].para.space_before, Some(12.0));assert_eq!(i.char_styles[0].chars.font_style.as_deref(), Some("Italic"));}++ #[test]+ fn tracked_changes_import_as_accepted_including_moves() {+ // Regression (#256): text in a tracked move destination (`w:moveTo`) vanished on import.+ let document = format!(+ r#"<w:document {W}><w:body>+ <w:p><w:r><w:t xml:space="preserve">Kept text. </w:t></w:r>+ <w:moveTo w:id="1" w:author="A"><w:r><w:t xml:space="preserve">MOVED HERE.</w:t></w:r>+ <w:del w:id="5" w:author="A"><w:r><w:delText>MOVED THEN DELETED</w:delText></w:r></w:del></w:moveTo>+ <w:r><w:t xml:space="preserve"> Plain </w:t></w:r>+ <w:ins w:id="2" w:author="A"><w:r><w:t>INSERTED</w:t></w:r></w:ins>+ <w:del w:id="3" w:author="A"><w:r><w:delText>DELETED</w:delText></w:r></w:del></w:p>+ <w:p><w:moveFrom w:id="4" w:author="A"><w:r><w:t>MOVED HERE.</w:t></w:r></w:moveFrom><w:r><w:t>End.</w:t></w:r></w:p>+ </w:body></w:document>"#+ );+ let i = import(&docx(&document, "", "")).unwrap();+ i.story.check().unwrap();+ assert_eq!(i.story.text, "Kept text. MOVED HERE. Plain INSERTED\nEnd.");+ }}