diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-05-26 15:14:39 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-05-27 11:01:16 +0200 |
commit | 3333d3e01e8ae9142f2e9ead1eb862af163bd843 (patch) | |
tree | 471141974e30a374e27e22e7605083ca06641281 /sw | |
parent | e2e7e4f277ed1cf1776499af0b5f6dc17010877d (diff) |
SwPaM::Find: fix backwards-search in shape text
Change-Id: I79157853d16ead4cb4147763ef0590702b3d8be6
(cherry picked from commit 122b149826d270b8cbb26e2044f8da25b1d29c25)
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/tiledrendering/tiledrendering.cxx | 22 | ||||
-rw-r--r-- | sw/source/core/crsr/findtxt.cxx | 58 |
2 files changed, 62 insertions, 18 deletions
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 756fb9b7cc03..4d6cc99c0baf 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 c15e5d1df3fd..741e307bcac3 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; |