Skip to content

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

Description

@fonskip

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions