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
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.
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?
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.
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...
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.
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.
> 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.
Created attachment 180751 [details] layout.xml
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 “bbbb”" type="REDLINE_DELETE"> I've attached layout.xml
This report is a duplicate. *** This bug has been marked as a duplicate of bug 134304 ***