Skip to content

Commit 345aeba

Browse files
authored
Merge pull request OpenXmlDev#18 from EricWhiteDev/vNext
Propagate run attributes when coalescing adjacent runs with identical…
2 parents f72d61e + 2a335d6 commit 345aeba

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

OpenXmlPowerTools/PtOpenXmlUtil.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -890,42 +890,39 @@ public static XElement CoalesceAdjacentRunsWithIdenticalFormatting(XElement runC
890890
IEnumerable<IEnumerable<XAttribute>> statusAtt =
891891
g.Select(r => r.Descendants(W.t).Take(1).Attributes(PtOpenXml.Status));
892892
return new XElement(W.r,
893+
g.First().Attributes(),
893894
g.First().Elements(W.rPr),
894895
new XElement(W.t, statusAtt, xs, textValue));
895896
}
896897

897898
if (g.First().Element(W.instrText) != null)
898899
return new XElement(W.r,
900+
g.First().Attributes(),
899901
g.First().Elements(W.rPr),
900902
new XElement(W.instrText, xs, textValue));
901903
}
902904

903905
if (g.First().Name == W.ins)
904906
{
905-
#if false
906-
if (g.First().Elements(W.del).Any())
907-
return new XElement(W.ins,
908-
g.First().Attributes(),
909-
new XElement(W.del,
910-
g.First().Elements(W.del).Attributes(),
911-
new XElement(W.r,
912-
g.First().Elements(W.del).Elements(W.r).Elements(W.rPr),
913-
new XElement(W.delText, xs, textValue))));
914-
#endif
907+
XElement firstR = g.First().Element(W.r);
915908
return new XElement(W.ins,
916909
g.First().Attributes(),
917910
new XElement(W.r,
911+
firstR?.Attributes(),
918912
g.First().Elements(W.r).Elements(W.rPr),
919913
new XElement(W.t, xs, textValue)));
920914
}
921915

922916
if (g.First().Name == W.del)
917+
{
918+
XElement firstR = g.First().Element(W.r);
923919
return new XElement(W.del,
924920
g.First().Attributes(),
925921
new XElement(W.r,
922+
firstR?.Attributes(),
926923
g.First().Elements(W.r).Elements(W.rPr),
927924
new XElement(W.delText, xs, textValue)));
928-
925+
}
929926
return g;
930927
}));
931928

0 commit comments

Comments
 (0)