sw/source/core/crsr/crsrsh.cxx |   13 +++++++++++++
 1 file changed, 13 insertions(+)

New commits:
commit 87f17803a907c29a121fcb84588da98a51cca543
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu Sep 15 11:24:32 2022 +0300
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Fri Sep 16 14:30:08 2022 +0200

    tdf#106959: use table's first content node for cursor cleanup
    
    The problem was that when doing the SHELL mail merge with a document
    starting with a table, the generated marks point to the first node on
    the page, which is not a content node, but a table node. When getting
    page numbers for such mark, cursor got cleaned up, meaning that it
    looked for a content node as the cursor position. The lookup tried
    to go to a previous content node first, and that gave a content node
    on the previous page.
    
    The cursor position cleanup was introduced for i#18014 in commit
    468c7b8d3287712c6959cd531c71875f4d26bcbc
      Author Jens-Heiner Rechtien <h...@openoffice.org>
      Date   Fri Jan 04 12:19:29 2008 +0000
        INTEGRATION: CWS sw8u10bf02 (1.66.92); FILE MERGED
    
    The bug was incorrect restoration of cursor position after inserting
    a row to a table, placing cursor there, and undoing.
    I have checked that the mentioned scenario keeps the cursor inside the
    table, not jumps to the beginning of the document, as it did before
    the mentined commit.
    
    Unfortunately, I don't see how to test this properly in
    sw/qa/extras/mailmerge/mailmerge.cxx; FILE mailmerge tests there use
    a different code path; and SHELL tests obviously do not perform the
    post-processing from SwMMResultSaveDialog::SaveOutputHdl_Impl. Likely,
    an UITest would be needed.
    
    But why do we use this SHELL + post-processing here, instead of using
    the same FILE mail merge that is performed from form letter dialog,
    when SwDBManager::Merge is called from SwDBManager::ExecuteFormLetter
    with properly constructed SwMergeDescriptor? That would also speed up
    the merge, avoiding extra steps of generating full resulting document
    in memory, saving it to a temporary file, just to split it to pieces
    (TODO/LATER).
    
    Change-Id: I269de4ae3407261c4f6df51cacd5fc72643fd29a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139973
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit eb30df9b8e86f756ebc66be86ae2eb345fafc850)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139983
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index 18199f2ebcd3..b24920da9b2f 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -3642,6 +3642,19 @@ void SwCursorShell::ClearUpCursors()
         pStartCursor->DeleteMark();
         bChanged = true;
     }
+    if (pStartCursor->GetPoint()->nNode.GetNode().IsTableNode())
+    {
+        // tdf#106959: When cursor points to start of a table, the proper 
content
+        // node is the first one inside the table, not the previous one
+        SwNodes& aNodes = GetDoc()->GetNodes();
+        SwNodeIndex aIdx(pStartCursor->GetPoint()->nNode);
+        if (SwNode* pNode = aNodes.GoNext(&aIdx))
+        {
+            SwPaM aTmpPam(*pNode);
+            *pStartCursor = aTmpPam;
+            bChanged = true;
+        }
+    }
     if( !sw_PosOk( *pStartCursor->GetPoint() ) )
     {
         SwNodes & aNodes = GetDoc()->GetNodes();

Reply via email to