https://bugs.documentfoundation.org/show_bug.cgi?id=148703

--- Comment #10 from David Hashe <[email protected]> ---
I think that I understand what's going on here.

Reproduction from empty documents:

1. Create a new document.
2. View > Styles. Click the "page styles" icon in the styles pane.
3. Right click an item and choose "new".
4. Apply, then OK.
5. Double click the newly created style in the styles pane to apply it.
6. Create a footer.
7. Insert some text into the footer (optional, but makes it clearer that the
footer is copied).
8. Enter at least two paragraphs (or more generally nodes) in the main body of
the first document.
9. Create a second new document.
10. Enter some text in the main body of the second document.
11. Ctrl-A then Ctrl-C in the first document.
12. Ctrl-A then Ctrl-V in the second document.
13. Ctrl-Z in the second document.

The source document must 1) have a non-default page style applied, and 2) have
a header and/or footer. The selection from the source document must also 3)
include at least two nodes. There also must 4) be a non-empty selection in the
destination document that is overwritten by the copy/paste, and 5) the
destination document can't already contain a page style with the same name as
the non-default page style from the source document selection.

When these conditions are met, the copy will include the header and/or footer
from the source document.

(See here, where the page desc, which exists if there is a page style applied,
is copied, which also copies the header/footer:
https://opengrok.libreoffice.org/xref/core/sw/source/core/attr/swatrset.cxx?r=ac3b217a43e21b00f434fa796a0c966b9ddfd9df#423
)

Pasting into the destination document is a two stage process, and then undoing
the paste is another two stage process:

1. Pasting into the destination document.
   a. Deleting the selection.
   b. Inserting the pasted content.
2. Undoing the paste.
   a. Deleting the pasted content.
   b. Re-inserting the selection.

In step 1a, the undo information saves the index from the document SwNodes
where it will re-insert the selection later.

(There's a comment about how undo information stores document indices here:
https://opengrok.libreoffice.org/xref/core/sw/source/core/undo/untblk.cxx?r=ac3b217a43e21b00f434fa796a0c966b9ddfd9df#239
)

By step 2b, something is wrong. The header/footer nodes are still in the
document, and it messes up the indexing, so the re-insertion point, which
should've been a text node, is actually a start node, which causes the cryptic
error.

The solution is to modify SwDoc::CopyPageDescHeaderFooterImpl to record the
copying of the header/footer nodes so that they are correctly undone and don't
mess up the indexing.

I am working on a small fix and regression test.

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to