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

Miklos Vajna vmiklos at collabora.co.uk
Tue May 26 06:37:30 PDT 2015


 sw/qa/extras/tiledrendering/tiledrendering.cxx |   22 ++++++---
 sw/source/core/crsr/findtxt.cxx                |   58 +++++++++++++++++++------
 2 files changed, 62 insertions(+), 18 deletions(-)

New commits:
commit 122b149826d270b8cbb26e2044f8da25b1d29c25
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue May 26 15:14:39 2015 +0200

    SwPaM::Find: fix backwards-search in shape text
    
    Change-Id: I79157853d16ead4cb4147763ef0590702b3d8be6

diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 756fb9b..4d6cc99 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -226,12 +226,12 @@ void SwTiledRenderingTest::testResetSelection()
 }
 
 #if !(defined WNT || defined MACOSX)
-void lcl_search()
+void lcl_search(bool bBackward)
 {
     uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence(
     {
         {"SearchItem.SearchString", uno::makeAny(OUString("shape"))},
-        {"SearchItem.Backward", uno::makeAny(false)}
+        {"SearchItem.Backward", uno::makeAny(bBackward)}
     }));
     comphelper::dispatchCommand(".uno:ExecuteSearch", aPropertyValues);
 }
@@ -245,24 +245,34 @@ void SwTiledRenderingTest::testSearch()
     size_t nNode = pWrtShell->getShellCrsr(false)->Start()->nNode.GetNode().GetIndex();
 
     // First hit, in the second paragraph, before the shape.
-    lcl_search();
+    lcl_search(false);
     CPPUNIT_ASSERT(!pWrtShell->GetDrawView()->GetTextEditObject());
     size_t nActual = pWrtShell->getShellCrsr(false)->Start()->nNode.GetNode().GetIndex();
     CPPUNIT_ASSERT_EQUAL(nNode + 1, nActual);
 
     // Next hit, in the shape.
-    lcl_search();
+    lcl_search(false);
     CPPUNIT_ASSERT(pWrtShell->GetDrawView()->GetTextEditObject());
 
     // Next hit, in the shape, still.
-    lcl_search();
+    lcl_search(false);
     CPPUNIT_ASSERT(pWrtShell->GetDrawView()->GetTextEditObject());
 
     // Last hit, in the last paragraph, after the shape.
-    lcl_search();
+    lcl_search(false);
     CPPUNIT_ASSERT(!pWrtShell->GetDrawView()->GetTextEditObject());
     nActual = pWrtShell->getShellCrsr(false)->Start()->nNode.GetNode().GetIndex();
     CPPUNIT_ASSERT_EQUAL(nNode + 7, nActual);
+
+    // Now change direction and make sure that the first 2 hits are in the shape, but not the 3rd one.
+    lcl_search(true);
+    CPPUNIT_ASSERT(pWrtShell->GetDrawView()->GetTextEditObject());
+    lcl_search(true);
+    CPPUNIT_ASSERT(pWrtShell->GetDrawView()->GetTextEditObject());
+    lcl_search(true);
+    CPPUNIT_ASSERT(!pWrtShell->GetDrawView()->GetTextEditObject());
+    nActual = pWrtShell->getShellCrsr(false)->Start()->nNode.GetNode().GetIndex();
+    CPPUNIT_ASSERT_EQUAL(nNode + 1, nActual);
 #endif
 }
 
diff --git a/sw/source/core/crsr/findtxt.cxx b/sw/source/core/crsr/findtxt.cxx
index c15e5d1..741e307 100644
--- a/sw/source/core/crsr/findtxt.cxx
+++ b/sw/source/core/crsr/findtxt.cxx
@@ -38,6 +38,7 @@
 #include <IDocumentUndoRedo.hxx>
 #include <IDocumentState.hxx>
 #include <IDocumentDrawModelAccess.hxx>
+#include <dcontact.hxx>
 #include <pamtyp.hxx>
 #include <ndtxt.hxx>
 #include <swundo.hxx>
@@ -302,9 +303,23 @@ bool SwPaM::Find( const SearchOptions& rSearchOpt, bool bSearchInNotes , utl::Te
             aSearchItem.SetBackward(!bSrchForward);
 
             // If there is an active text edit, then search there.
-            if (SdrView* pSdrView = pWrtShell->GetDrawView())
+            bool bEndedTextEdit = false;
+            SdrView* pSdrView = pWrtShell->GetDrawView();
+            if (pSdrView)
             {
-                if (pSdrView->GetTextEditObject())
+                // If the edited object is not anchored to this node, then ignore it.
+                SdrObject* pObject = pSdrView->GetTextEditObject();
+                if (pObject)
+                {
+                    if (SwFrameFormat* pFrameFormat = FindFrameFormat(pObject))
+                    {
+                        const SwPosition* pPosition = pFrameFormat->GetAnchor().GetContentAnchor();
+                        if (!pPosition || pPosition->nNode.GetIndex() != pNode->GetIndex())
+                            pObject = 0;
+                    }
+                }
+
+                if (pObject)
                 {
                     sal_uInt16 nResult = pSdrView->GetTextEditOutlinerView()->StartSearchAndReplace(aSearchItem);
                     if (!nResult)
@@ -315,6 +330,7 @@ bool SwPaM::Find( const SearchOptions& rSearchOpt, bool bSearchInNotes , utl::Te
                         pSdrView->UnmarkAll();
                         pWrtShell->SetCursor(&aPoint, true);
                         pWrtShell->Edit();
+                        bEndedTextEdit = true;
                     }
                     else
                     {
@@ -324,17 +340,35 @@ bool SwPaM::Find( const SearchOptions& rSearchOpt, bool bSearchInNotes , utl::Te
                 }
             }
 
-            // If there are any shapes anchored to this node, search there.
-            SwPaM aPaM(pNode->GetDoc()->GetNodes().GetEndOfContent());
-            aPaM.GetPoint()->nNode = rTextNode;
-            aPaM.GetPoint()->nContent.Assign(aPaM.GetPoint()->nNode.GetNode().GetTextNode(), nStart);
-            aPaM.SetMark();
-            aPaM.GetMark()->nNode = rTextNode.GetIndex() + 1;
-            aPaM.GetMark()->nContent.Assign(aPaM.GetMark()->nNode.GetNode().GetTextNode(), 0);
-            if (pNode->GetDoc()->getIDocumentDrawModelAccess().Search(aPaM, aSearchItem))
+            // If we just finished search in shape text, don't attept to do that again.
+            if (!bEndedTextEdit)
             {
-                bFound = true;
-                break;
+                // If there are any shapes anchored to this node, search there.
+                SwPaM aPaM(pNode->GetDoc()->GetNodes().GetEndOfContent());
+                aPaM.GetPoint()->nNode = rTextNode;
+                aPaM.GetPoint()->nContent.Assign(aPaM.GetPoint()->nNode.GetNode().GetTextNode(), nStart);
+                aPaM.SetMark();
+                aPaM.GetMark()->nNode = rTextNode.GetIndex() + 1;
+                aPaM.GetMark()->nContent.Assign(aPaM.GetMark()->nNode.GetNode().GetTextNode(), 0);
+                if (pNode->GetDoc()->getIDocumentDrawModelAccess().Search(aPaM, aSearchItem) && pSdrView)
+                {
+                    if (SdrObject* pObject = pSdrView->GetTextEditObject())
+                    {
+                        if (SwFrameFormat* pFrameFormat = FindFrameFormat(pObject))
+                        {
+                            const SwPosition* pPosition = pFrameFormat->GetAnchor().GetContentAnchor();
+                            if (pPosition)
+                            {
+                                // Set search position to the shape's anchor point.
+                                *GetPoint() = *pPosition;
+                                GetPoint()->nContent.Assign(pPosition->nNode.GetNode().GetContentNode(), 0);
+                                SetMark();
+                                bFound = true;
+                                break;
+                            }
+                        }
+                    }
+                }
             }
 
             sal_Int32 aStart = 0;


More information about the Libreoffice-commits mailing list