Skip to content

Conversation

@reindervdw-cmi
Copy link
Contributor

No description provided.

@reindervdw-cmi reindervdw-cmi requested a review from Copilot July 11, 2025 15:13
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses an issue where restore_comments was inadvertently stripping all but the last comment reference in a paragraph. Key changes include:

  • Adding a new test to verify that comment references are preserved when restoring comments.
  • Simplifying the cleanup logic in restore_comments to only remove runs with no children.
  • Bumping the project version from 0.4.1 to 0.4.2.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/test_comment.py Added test_restore_comments_preserves_comment_references to cover multiple comment references.
src/cmi_docx/comment.py Changed cleanup loop in restore_comments to only remove runs with zero child elements.
pyproject.toml Updated package version to 0.4.2.

Comment on lines +328 to 330
if elem.tag == f"{{{self.ns['w']}}}r" and len(elem) == 0:
self.paragraph.remove(elem)

Copy link

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cleanup loop now only removes runs with no child elements, but runs containing only styling properties (e.g., <w:rPr>) without any text will be retained. Consider extending this condition to also remove runs that have no <w:t> children or delegate to the existing should_remove_run logic to ensure all empty/comment-only runs are cleaned up before appending references.

Suggested change
if elem.tag == f"{{{self.ns['w']}}}r" and len(elem) == 0:
self.paragraph.remove(elem)
if elem.tag == f"{{{self.ns['w']}}}r" and self.should_remove_run(elem):
self.paragraph.remove(elem)
def should_remove_run(self, run_elem: etree._Element) -> bool:
"""Determine if a run element should be removed."""
# Check if the run has no child elements
if len(run_elem) == 0:
return True
# Check if the run contains only styling properties (<w:rPr>) without text (<w:t>)
text_elems = run_elem.findall(f".//{{{self.ns['w']}}}t")
if not text_elems:
return True
return False

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Jul 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.92%. Comparing base (c58d98a) to head (99fc2a7).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #48   +/-   ##
=======================================
  Coverage   83.92%   83.92%           
=======================================
  Files           7        7           
  Lines         504      504           
=======================================
  Hits          423      423           
  Misses         81       81           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@reindervdw-cmi reindervdw-cmi merged commit e6963a5 into main Jul 11, 2025
30 checks passed
@reindervdw-cmi reindervdw-cmi deleted the fix/comment-removed-in-find-replace branch July 11, 2025 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants