bug issue with text replace and XML

This commit is contained in:
Xamora 2025-07-10 10:53:14 +02:00
parent f487132af9
commit ecf8ab977a

View file

@ -75,11 +75,11 @@ class DocxEditor {
if (texts.isEmpty)
continue;
String original = texts.map((t) {
final String original = texts.map((t) {
return t.innerText;
}).join();
String replaced = original.replaceAllMapped(pattern, (match) {
final String replaced = original.replaceAllMapped(pattern, (match) {
ReplaceContent rc = replaceMap[match[0]]!;
return rc.img == null ? rc.value! : '';
});
@ -87,12 +87,10 @@ class DocxEditor {
if (original == replaced)
continue;
final firstRun = paragraph.findElements('w:r').first;
final newRun = firstRun.copy();
newRun.findAllElements('w:t').first.innerText = replaced; // Update with new text
// replace the first w:r with the new
firstRun.replace(newRun);
XmlElement firstRun = paragraph.findElements('w:r').first;
for (XmlElement xmlText in paragraph.findAllElements('w:t')) // clear text
xmlText.innerText = '';
firstRun.findAllElements('w:t').first.innerText = replaced;
}
return [documentXml, documentXmlRels];