Keep comment anchors when assigning paragraph.text - #1605
Conversation
clear() dropped commentRangeStart/End and the comment reference run, so comments.xml kept a comment with nothing pointing at it.
|
Thanks for picking this up. I tested the logic in this PR against python-docx 1.2.0 and it does fix the comment case: before 3 markers / 1 comment, after Three notes, in case they're useful before review. 1. Footnote references and tracked changes are still dropped. Running the same logic on a document that has a footnote reference in the paragraph:
2. The comment range widens to the whole paragraph. If the comment was anchored to a few words inside the paragraph, it now covers all of the replacement text. I think that's the only sensible behaviour for a full-text replacement, and it matches what Word does when you retype a commented passage, but it's worth stating in the docstring rather than leaving as an implicit side effect — otherwise someone will read "stay anchored" as "anchored to the same span". 3. Pre-existing bug this PR surfaces: the reference run gets Happy to file that as a separate issue if you'd rather keep this PR focused. (Same gap existed in adeu and was fixed in their 3.0.3, for reference.) Checked with ooxml-integrity against the source document, python-docx 1.2.0, Python 3.9.6, macOS. |
A full-text assignment cannot keep the original word span, and footnotes plus tracked changes still drop. Say that on the property so it is not read as preserving the original anchor.
|
Thanks for checking this against 1.2.0. Kept the PR on comments. Footnotes and The docstring now states the range covers the whole replacement run. The missing CommentReference style is outside this change, as you said. A separate issue is the right place if you want to file it. |
Setting
paragraph.textrunsclear(), which droppedw:commentRangeStart/w:commentRangeEndand the comment reference run. The comment body stayed in comments.xml with nothing pointing at it.Collect the previous comment ids and re-mark them on the replacement run. The range then covers that whole run, not the original word span.
This is the comment half of #1604. Footnote references and tracked-change markup still drop on
clear().