sw/qa/extras/layout/data/tdf141079.odt |binary
 sw/qa/extras/layout/layout2.cxx        |   33 +++++++++++++++++++++++++++++++++
 sw/source/core/text/itrcrsr.cxx        |    8 ++++++--
 3 files changed, 39 insertions(+), 2 deletions(-)

New commits:
commit 5302268de6a33716c7746aa13232746ad2f2b561
Author:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
AuthorDate: Thu Mar 18 11:41:29 2021 +0100
Commit:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
CommitDate: Thu Mar 25 07:23:55 2021 +0100

    tdf#141079 Restore double click behavior for script fields
    
    Change-Id: I5daa730740ea042bdae56b832f2557ec974339b3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112668
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>

diff --git a/sw/qa/extras/layout/data/tdf141079.odt 
b/sw/qa/extras/layout/data/tdf141079.odt
new file mode 100644
index 000000000000..65dfcb4a296f
Binary files /dev/null and b/sw/qa/extras/layout/data/tdf141079.odt differ
diff --git a/sw/qa/extras/layout/layout2.cxx b/sw/qa/extras/layout/layout2.cxx
index ed0db4a81ee8..023c9b6aa61a 100644
--- a/sw/qa/extras/layout/layout2.cxx
+++ b/sw/qa/extras/layout/layout2.cxx
@@ -2066,6 +2066,39 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testImageComment)
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5), 
aPosition.nContent.GetIndex());
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testScriptField)
+{
+    // Test clicking script field inside table ( tdf#141079 )
+    SwDoc* pDoc = createDoc("tdf141079.odt");
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+
+    // Look up layout position which is the first cell in the table
+    SwRootFrame* pRoot = pWrtShell->GetLayout();
+    CPPUNIT_ASSERT(pRoot->GetLower()->IsPageFrame());
+    SwPageFrame* pPage = static_cast<SwPageFrame*>(pRoot->GetLower());
+    CPPUNIT_ASSERT(pPage->GetLower()->IsBodyFrame());
+    SwBodyFrame* pBody = static_cast<SwBodyFrame*>(pPage->GetLower());
+    CPPUNIT_ASSERT(pBody->GetLower()->IsTextFrame());
+    SwTextFrame* pTextFrame = static_cast<SwTextFrame*>(pBody->GetLower());
+    CPPUNIT_ASSERT(pTextFrame->GetNext()->IsTabFrame());
+    SwFrame* pTable = pTextFrame->GetNext();
+    SwFrame* pRow1 = pTable->GetLower();
+    CPPUNIT_ASSERT(pRow1->GetLower()->IsCellFrame());
+    SwFrame* pCell1 = pRow1->GetLower();
+    CPPUNIT_ASSERT(pCell1->GetLower()->IsTextFrame());
+    SwTextFrame* pCellTextFrame = 
static_cast<SwTextFrame*>(pCell1->GetLower());
+    const SwRect& rCellRect = pCell1->getFrameArea();
+    Point aPoint = rCellRect.Center();
+    aPoint.setX(aPoint.getX() - rCellRect.Width() / 2);
+
+    // Ask for the doc model pos of this layout point.
+    SwPosition aPosition(*pCellTextFrame->GetTextNodeForFirstText());
+    pCellTextFrame->GetModelPositionForViewPoint(&aPosition, aPoint);
+
+    // Position was 1 without the fix from tdf#141079
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), 
aPosition.nContent.GetIndex());
+}
+
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testCommentCursorPosition)
 {
     // Load a document that has "aaa" in it, followed by three comments.
diff --git a/sw/source/core/text/itrcrsr.cxx b/sw/source/core/text/itrcrsr.cxx
index 9a1f7140b52f..4c39874eb862 100644
--- a/sw/source/core/text/itrcrsr.cxx
+++ b/sw/source/core/text/itrcrsr.cxx
@@ -1560,8 +1560,12 @@ TextFrameIndex 
SwTextCursor::GetModelPositionForViewPoint( SwPosition *pPos, con
             {
                 if (pPor->IsPostItsPortion())
                 {
-                    // Offset would be nCurrStart + nLength below, do the same 
for post-it portions.
-                    nCurrStart += pPor->GetLen();
+                    SwPostItsPortion* pPostItsPortion = 
dynamic_cast<SwPostItsPortion*>(pPor);
+                    if (!pPostItsPortion->IsScript()) // tdf#141079
+                    {
+                        // Offset would be nCurrStart + nLength below, do the 
same for post-it portions.
+                        nCurrStart += pPor->GetLen();
+                    }
                 }
                 return nCurrStart;
             }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to