[Libreoffice-commits] core.git: sw/qa sw/source

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Fri Jan 3 14:35:38 UTC 2020


 sw/qa/extras/unowriter/unowriter.cxx |   22 +++++++++++-----------
 sw/source/core/crsr/crsrsh.cxx       |   18 +++++++++++++-----
 2 files changed, 24 insertions(+), 16 deletions(-)

New commits:
commit 0fce75bde16d64970feab5de488da530193dfa23
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Fri Jan 3 01:33:20 2020 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Fri Jan 3 15:35:00 2020 +0100

    tdf#129743 follow-up: implement the other variant of the fix
    
    Reimplement commit d8a188d8d59ae51621a0540fe931e1c70db285fe
    
    Seems that I was overly optimistic. The behaviour of CreateCursor
    affects many places; first of them is CreateNewShellCursor, which
    would start returning cursors with selection after the fix from
    commit d8a188d8d59ae51621a0540fe931e1c70db285fe. Or if we change
    which cursor is returned from that method, then the order of the
    chain would reverse. And there are many such places. So just make
    it like before, and do the conservative fix.
    
    Change-Id: Ib6bf414f0e91d6fb59f73fbfc0fbd799457d49c9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86151
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx
index 2f01c47605ba..3d3301130388 100644
--- a/sw/qa/extras/unowriter/unowriter.cxx
+++ b/sw/qa/extras/unowriter/unowriter.cxx
@@ -793,7 +793,7 @@ CPPUNIT_TEST_FIXTURE(SwUnoWriter, testMultiSelect)
     loadURL("private:factory/swriter", nullptr);
     uno::Reference<text::XTextDocument> xTextDocument(mxComponent, css::uno::UNO_QUERY_THROW);
     auto xSimpleText = xTextDocument->getText();
-    xSimpleText->insertString(xSimpleText->getStart(), "abc abc abc", false);
+    xSimpleText->insertString(xSimpleText->getStart(), "Abc aBc abC", false);
 
     // Create a search descriptor and find all occurencies of search string
     css::uno::Reference<css::util::XSearchable> xSearchable(mxComponent, css::uno::UNO_QUERY_THROW);
@@ -802,7 +802,7 @@ CPPUNIT_TEST_FIXTURE(SwUnoWriter, testMultiSelect)
     xSearchDescriptor->setPropertyValue("SearchCaseSensitive", css::uno::Any(false));
     xSearchDescriptor->setPropertyValue("SearchBackwards", css::uno::Any(true));
     xSearchDescriptor->setPropertyValue("SearchRegularExpression", css::uno::Any(false));
-    xSearchDescriptor->setSearchString("Abc");
+    xSearchDescriptor->setSearchString("abc");
     auto xSearchResult = xSearchable->findAll(xSearchDescriptor);
 
     // Select them all
@@ -812,16 +812,16 @@ CPPUNIT_TEST_FIXTURE(SwUnoWriter, testMultiSelect)
     xSelectionSupplier->select(css::uno::Any(xSearchResult));
     css::uno::Reference<css::container::XIndexAccess> xSelection(xSelectionSupplier->getSelection(),
                                                                  css::uno::UNO_QUERY_THROW);
-    // Now check that they all are selected.
+    // Now check that they all are selected in the reverse order ("SearchBackwards").
     CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xSelection->getCount());
-    for (sal_Int32 i = 0; i < xSelection->getCount(); ++i)
-    {
-        css::uno::Reference<css::text::XTextRange> xTextRange(xSelection->getByIndex(i),
-                                                              css::uno::UNO_QUERY_THROW);
-        // For i=0, result was empty (cursor was put before the last occurence without selection)
-        const OString sComment = "i=" + OString::number(i);
-        CPPUNIT_ASSERT_EQUAL_MESSAGE(sComment.getStr(), OUString("abc"), xTextRange->getString());
-    }
+    css::uno::Reference<css::text::XTextRange> xTextRange(xSelection->getByIndex(0),
+                                                          css::uno::UNO_QUERY_THROW);
+    // For #0, result was empty (cursor was put before the last occurence without selection)
+    CPPUNIT_ASSERT_EQUAL(OUString("abC"), xTextRange->getString());
+    xTextRange.set(xSelection->getByIndex(1), css::uno::UNO_QUERY_THROW);
+    CPPUNIT_ASSERT_EQUAL(OUString("aBc"), xTextRange->getString());
+    xTextRange.set(xSelection->getByIndex(2), css::uno::UNO_QUERY_THROW);
+    CPPUNIT_ASSERT_EQUAL(OUString("Abc"), xTextRange->getString());
 }
 
 CPPUNIT_TEST_FIXTURE(SwUnoWriter, testTransparentText)
diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index 29293a841ebe..1e8f8fe7a90a 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -114,6 +114,10 @@ static void CheckRange( SwCursor* pCurrentCursor )
 
 // SwCursorShell
 
+/**
+ * Add a copy of current cursor, append it after current, and collapse current cursor.
+ * @return - Returns a newly created copy of current cursor.
+ */
 SwPaM * SwCursorShell::CreateCursor()
 {
     // don't create new Cursor with active table Selection
@@ -127,6 +131,8 @@ SwPaM * SwCursorShell::CreateCursor()
     // copied PaM (#i75172#)
     pNew->swapContent(*m_pCurrentCursor);
 
+    m_pCurrentCursor->DeleteMark();
+
     UpdateCursor( SwCursorShell::SCROLLWIN );
     return pNew;
 }
@@ -3482,11 +3488,6 @@ void SwCursorShell::SetSelection( const SwPaM& rCursor )
     StartAction();
     SwPaM* pCursor = GetCursor();
     *pCursor->GetPoint() = *rCursor.GetPoint();
-    if(rCursor.HasMark())
-    {
-        pCursor->SetMark();
-        *pCursor->GetMark() = *rCursor.GetMark();
-    }
     if(rCursor.GetNext() != &rCursor)
     {
         const SwPaM *_pStartCursor = rCursor.GetNext();
@@ -3501,6 +3502,13 @@ void SwCursorShell::SetSelection( const SwPaM& rCursor )
             }
         } while( (_pStartCursor = _pStartCursor->GetNext()) != &rCursor );
     }
+    // CreateCursor() adds a copy of current cursor after current, and then deletes mark of current
+    // cursor; therefore set current cursor's mark only after creating all other cursors
+    if (rCursor.HasMark())
+    {
+        pCursor->SetMark();
+        *pCursor->GetMark() = *rCursor.GetMark();
+    }
     EndAction();
 }
 


More information about the Libreoffice-commits mailing list