Bug 160814 - DOCX comments (replies) are in the wrong order
Summary: DOCX comments (replies) are in the wrong order
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
4.3 all versions
Hardware: All All
: medium normal
Assignee: Justin L
URL:
Whiteboard: target:24.8.0
Keywords: bibisected, bisected, regression
Depends on:
Blocks: DOCX-Comments
  Show dependency treegraph
 
Reported: 2024-04-24 18:45 UTC by Justin L
Modified: 2024-05-07 11:09 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
commentsInWordD.docx: this hand-crafted version isn't solved, but that is out of scope. (15.82 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2024-05-07 11:09 UTC, Justin L
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Justin L 2024-04-24 18:45:19 UTC
Comments in a DOCX file might not import in the correct order.

Steps to reproduce.
1.) Open commentsInWord.docx (attachment 193829 [details] from bug 160350)

The order of the comments should look like attachment 193828 [details].

The comments were correctly ordered until LO 4.3's
commit 0761f81643a6890457e9ef7d913ab5c88c2593a4
Author: Oliver-Rainer on Wed Jan 8 15:58:35 2014 +0100
    123792: complete annotations on text ranges feature
Comment 1 Justin L 2024-04-24 19:43:29 UTC
The order they appear in word/comments.xml is the order in which they should appear in the document as well (at least for this example).

Based on reading the 4.3 patch's writerfilter code, I don't see anything that would change the order. Indeed, it still calls PopAnnotation in this order:
0 // First coment (note that the 1 is from list numbering - which is lost in LO)
1 // 1.1 second reply.
3 // 1.2 third reply. Only reply on whole thread…
5 // 1.3
2 // 2. second comment
4 // 2.1
Comment 2 Justin L 2024-04-24 23:27:18 UTC
If I disable NS_ooxml::LN_EG_RangeMarkupElements_commentRangeEnd (so there is no range, just a single entry point) then the comments are back in the right order.

So the problem is related to the fact that w:commentRangeEnd w:id="2/3/4"/> comes before <w:commentReference w:id="3"/> is inserted. Thus the remaining comments (2 and 4) try to import into
SwPaM start[SwPosition (node 9, offset 10)] mark[SwPosition (node 9, offset 10)]
Comment 3 Justin L 2024-04-27 00:18:53 UTC
A wild attempt at a fix is at https://gerrit.libreoffice.org/c/core/+/166765
Comment 4 Commit Notification 2024-05-06 07:10:44 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/7ae84ed99b133cdb4c197ecb43e2454f90b0439a

tdf#160814 writerfilter: insert comment after other comments

It will be available in 24.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 5 Commit Notification 2024-05-07 06:47:40 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/e7ea91a4af1242fcfa5f5ba5f04bbc6662453e28

tdf#160814 writerfilter: insert comment after other comments #2

It will be available in 24.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 6 Justin L 2024-05-07 11:09:43 UTC
Created attachment 194014 [details]
commentsInWordD.docx: this hand-crafted version isn't solved, but that is out of scope.