Bug 149453 - Copy-paste with changes showing deletions
Summary: Copy-paste with changes showing deletions
Status: RESOLVED DUPLICATE of bug 134304
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
7.4.0.0 alpha0+
Hardware: All All
: medium enhancement
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-06-04 13:25 UTC by ThomasU
Modified: 2022-06-14 13:14 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
layout.xml (3.16 KB, text/xml)
2022-06-14 10:28 UTC, ThomasU
Details

Note You need to log in before you can comment on or make changes to this bug.
Description ThomasU 2022-06-04 13:25:29 UTC
This is a well known and long sought feature request but I couldn't find the bug report for it:
In Track Changes mode, there is a need to be able to copy-paste paragraphs containing underlined additions and striked-through deletions from a first document to a second document.

For example, the second document is written as a report of amendments made in the first document. This is needed when drafting a response to a patent examiner.

Can somebody work on this feature request?

Discussions requesting this feature include:
In 2020: 
https://ask.libreoffice.org/t/writer-copy-paste-text-with-changes-record-track-changes/54707

In 2018:
https://ask.libreoffice.org/t/writer-track-changes-how-to-copy-with-changes/31930

In 2017:
https://ask.libreoffice.org/t/cutting-and-pasting-text-with-tracked-changes/23622

In 2014:
https://ask.libreoffice.org/t/move-copy-text-containing-tracked-changes/7208

In 2012:
https://ask.libreoffice.org/t/writer-copy-paste-change-tracking-markup/2248
Comment 1 ThomasU 2022-06-07 09:17:51 UTC
I'd like to try implement such a copy-paste of tracking mode additions and deletions as a macro.
Looking into the XML file I can see those additions and deletions.
However, trying out the macro at 
https://wiki.documentfoundation.org/Macros/General/008
I could see that, even in Tracking mode, selecting a deleted chunk of text, then typing ctrl-c, does not place that deleted chunk of text into the clipboard.

Is there a function usable in a macro in Tracking mode that can copy selected "added" and "deleted" chunks of text into the clipboard as such? 
Then I could re-use that text in a macro for pasting into a document.

Thanks for any input.
Comment 2 Miklos Vajna 2022-06-07 09:25:22 UTC
If you have a simple document: "aaabbbccc\n" (9 characters and a newline), then you turn recording changes on, and delete bbb, then you'll have an entry in the SwDoc's SwRedlineTable. That entry will have a type of REDLINE_DELETE and it'll have a start posisition of (9,3) (node index, character index) and end position of (9, 6).

I'm not sure how the macro API for redlines look like, but internally the task would be to make sure that when you copy the whole first paragraph to the second one, then you don't copy the "view" of that paragraph but rather the document model (SwTextNode) text, and also create a second entry in the redline table, which would then point to (10,3) -> (10,3) with the delete type.

If you start soffice with the SW_DEBUG=1 environment variable, then Shift-F12 will give you a nodes.xml which shows the internal document model for you.

For the pasting code, look into SwBaseShell::ExecClpbrd(), the SID_PASTE case is probably relevant.

Is this enough code pointers to get you started?
Comment 3 ThomasU 2022-06-09 23:30:01 UTC
Thank you, Miklos, for offering to help. I'm a beginner.
I'm not sure there's an API to access SwRedlineTable.
I see void SwRedlineTable::dumpAsXml(xmlTextWriterPtr pWriter) const
at line 857 of https://docs.libreoffice.org/sw/html/docredln_8cxx_source.html#l00417

Despite some attempts, I don't know how to go beyond that.
If dumpAsXml is callable from a macro, then a short example could maybe get me started.
Comment 4 Michael Stahl (allotropia) 2022-06-10 09:28:20 UTC
this dumpAsXml stuff is only hooked up to keyboard shortcuts, you may be able to trigger it by sending Shift+F12 keyboard input event while Writer has focus.

i know that the UITests do these things via com.sun.star.ui.test.XUIObject.executeAction, but probably it's not the only way...
Comment 5 Miklos Vajna 2022-06-13 07:50:06 UTC
Perhaps it's good to consider the broader context and forget about the UNO API for now. The actual text copying code is all under sw/ (see above), that has to be improved to not skip but properly copy deleted text, I guess.
Comment 6 ThomasU 2022-06-13 08:42:38 UTC
Thanks, Miklos.
To be more precise, the problem is about text selection.
Selecting text that contains striked-through "deleted" text does not add the striked-through text onto the clipboard.
What could be helpful would be to code an option so that selecting text also selects striked-through text along with formatting info.
I have not yet been able to find what file in the LibreOffice source code contains the functions handling text selection.
A link would be helpful.
Many thanks.
Comment 7 Miklos Vajna 2022-06-14 06:53:04 UTC
> To be more precise, the problem is about text selection.

Hm, how did you arrive to that conclusion?

If you create a selection that contains deleted (but visible) text and you follow the instructions from comment 2 to enable the debug xml dump, then F12 will show you that the selection contains the deleted text (look for m_pCurrentCursor in layout.xml, the length of the selection is visible from the point and mark's content index), I expect that the copying is at fault.

Please use the code pointer from comment 2 and do a bit of research yourself before asking more questions. Thanks.
Comment 8 ThomasU 2022-06-14 10:28:16 UTC
Created attachment 180751 [details]
layout.xml
Comment 9 ThomasU 2022-06-14 10:30:29 UTC
Thanks. After struggling a while I found out that the SW_DEBUG=1 "environment variable" should not be defined in the bash environment of the terminal I use to launch LibreOffice but rather in the soffice command line. I needed more precise instructions. I'm not in the same world as yours!

What's needed on the command line is:
/opt/libreofficedev7.3/program/swriter -env:SW_DEBUG=1

Your F12 is based on what is described on line 25 of:
https://cgit.freedesktop.org/libreoffice/core/tree/sw/qa/extras/README

Then I type "aaaa bbbb cccc"
Enter tracking mode
Delete bbbb which becomes striked out
Then type F12
Then files nodes.xml and layout.xml get dumped in the folder where I started swriter.

Then on line 270 of nodes.xml I see:
<SwRangeRedline ptr="0x2295b40" id="0" author="TU" date="2022-06-14T12:06:39Z" descr="Delete &#x201C;bbbb&#x201D;" type="REDLINE_DELETE">

I've attached layout.xml
Comment 10 Timur 2022-06-14 13:14:05 UTC
This report is a duplicate.

*** This bug has been marked as a duplicate of bug 134304 ***