Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved text in tracked changes is duplicated when using paragraph.raw_text() #794

Open
fonskip opened this issue Jan 9, 2025 · 0 comments · May be fixed by #795
Open

Moved text in tracked changes is duplicated when using paragraph.raw_text() #794

fonskip opened this issue Jan 9, 2025 · 0 comments · May be fixed by #795
Labels
bug Something isn't working

Comments

@fonskip
Copy link

fonskip commented Jan 9, 2025

Description

When calling paragraph.raw_text() on a Paragraph with changes that are not yet accepted, the expected behavior in to see the paragraph’s text as if all the tracked changes had been accepted. But tracked changes corresponding to a "move" operation are duplicated.

Steps to reproduce

  1. Create a Word document manually with 2 different lines
  2. Print the text with paragraph.raw_text() -> output gives the same 2 lines
  3. Activate the Track Changes feature, and then cut and paste the second line -> it is considered "moved"
  4. Print the text again -> output gives 3 lines, with the second one being duplicated

Expected behavior

The second line should not be printed twice.

## Suggestion

A moved element in a docx file corresponds to a "w:moveFrom" followed by a "w:moveTo" element in the document.xml
IMO, those XML elements should be added to the XMLElement and ParagraphChild enums. This requires a bit of refactor. Then, the raw_text method from Paragraph should be added a new match arm for the ParagraphChild::MoveTo case, which would print the Run’s text.

I’ve made a quick fix myself for my needs, I will submit a PR soon with my changes. The fix seems to solve the problem for my very precise needs, but it is definitely not enough for it to be accepted and it needs some more work. It also adds quite a lot of duplicate code, so there is probably a better way to achieve it using Traits.

Desktop

  • OS: Debian 12
  • Version: "0.4.18-rc19"
@fonskip fonskip added the bug Something isn't working label Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant