Kaydet (Commit) 3333d3e0 authored tarafından Miklos Vajna's avatar Miklos Vajna

SwPaM::Find: fix backwards-search in shape text

Change-Id: I79157853d16ead4cb4147763ef0590702b3d8be6
(cherry picked from commit 122b1498)
üst e2e7e4f2
...@@ -226,12 +226,12 @@ void SwTiledRenderingTest::testResetSelection() ...@@ -226,12 +226,12 @@ void SwTiledRenderingTest::testResetSelection()
} }
#if !(defined WNT || defined MACOSX) #if !(defined WNT || defined MACOSX)
void lcl_search() void lcl_search(bool bBackward)
{ {
uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence( uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence(
{ {
{"SearchItem.SearchString", uno::makeAny(OUString("shape"))}, {"SearchItem.SearchString", uno::makeAny(OUString("shape"))},
{"SearchItem.Backward", uno::makeAny(false)} {"SearchItem.Backward", uno::makeAny(bBackward)}
})); }));
comphelper::dispatchCommand(".uno:ExecuteSearch", aPropertyValues); comphelper::dispatchCommand(".uno:ExecuteSearch", aPropertyValues);
} }
...@@ -245,24 +245,34 @@ void SwTiledRenderingTest::testSearch() ...@@ -245,24 +245,34 @@ void SwTiledRenderingTest::testSearch()
size_t nNode = pWrtShell->getShellCrsr(false)->Start()->nNode.GetNode().GetIndex(); size_t nNode = pWrtShell->getShellCrsr(false)->Start()->nNode.GetNode().GetIndex();
// First hit, in the second paragraph, before the shape. // First hit, in the second paragraph, before the shape.
lcl_search(); lcl_search(false);
CPPUNIT_ASSERT(!pWrtShell->GetDrawView()->GetTextEditObject()); CPPUNIT_ASSERT(!pWrtShell->GetDrawView()->GetTextEditObject());
size_t nActual = pWrtShell->getShellCrsr(false)->Start()->nNode.GetNode().GetIndex(); size_t nActual = pWrtShell->getShellCrsr(false)->Start()->nNode.GetNode().GetIndex();
CPPUNIT_ASSERT_EQUAL(nNode + 1, nActual); CPPUNIT_ASSERT_EQUAL(nNode + 1, nActual);
// Next hit, in the shape. // Next hit, in the shape.
lcl_search(); lcl_search(false);
CPPUNIT_ASSERT(pWrtShell->GetDrawView()->GetTextEditObject()); CPPUNIT_ASSERT(pWrtShell->GetDrawView()->GetTextEditObject());
// Next hit, in the shape, still. // Next hit, in the shape, still.
lcl_search(); lcl_search(false);
CPPUNIT_ASSERT(pWrtShell->GetDrawView()->GetTextEditObject()); CPPUNIT_ASSERT(pWrtShell->GetDrawView()->GetTextEditObject());
// Last hit, in the last paragraph, after the shape. // Last hit, in the last paragraph, after the shape.
lcl_search(); lcl_search(false);
CPPUNIT_ASSERT(!pWrtShell->GetDrawView()->GetTextEditObject()); CPPUNIT_ASSERT(!pWrtShell->GetDrawView()->GetTextEditObject());
nActual = pWrtShell->getShellCrsr(false)->Start()->nNode.GetNode().GetIndex(); nActual = pWrtShell->getShellCrsr(false)->Start()->nNode.GetNode().GetIndex();
CPPUNIT_ASSERT_EQUAL(nNode + 7, nActual); 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 #endif
} }
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <IDocumentUndoRedo.hxx> #include <IDocumentUndoRedo.hxx>
#include <IDocumentState.hxx> #include <IDocumentState.hxx>
#include <IDocumentDrawModelAccess.hxx> #include <IDocumentDrawModelAccess.hxx>
#include <dcontact.hxx>
#include <pamtyp.hxx> #include <pamtyp.hxx>
#include <ndtxt.hxx> #include <ndtxt.hxx>
#include <swundo.hxx> #include <swundo.hxx>
...@@ -302,9 +303,23 @@ bool SwPaM::Find( const SearchOptions& rSearchOpt, bool bSearchInNotes , utl::Te ...@@ -302,9 +303,23 @@ bool SwPaM::Find( const SearchOptions& rSearchOpt, bool bSearchInNotes , utl::Te
aSearchItem.SetBackward(!bSrchForward); aSearchItem.SetBackward(!bSrchForward);
// If there is an active text edit, then search there. // 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); sal_uInt16 nResult = pSdrView->GetTextEditOutlinerView()->StartSearchAndReplace(aSearchItem);
if (!nResult) if (!nResult)
...@@ -315,6 +330,7 @@ bool SwPaM::Find( const SearchOptions& rSearchOpt, bool bSearchInNotes , utl::Te ...@@ -315,6 +330,7 @@ bool SwPaM::Find( const SearchOptions& rSearchOpt, bool bSearchInNotes , utl::Te
pSdrView->UnmarkAll(); pSdrView->UnmarkAll();
pWrtShell->SetCursor(&aPoint, true); pWrtShell->SetCursor(&aPoint, true);
pWrtShell->Edit(); pWrtShell->Edit();
bEndedTextEdit = true;
} }
else else
{ {
...@@ -324,17 +340,35 @@ bool SwPaM::Find( const SearchOptions& rSearchOpt, bool bSearchInNotes , utl::Te ...@@ -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. // If we just finished search in shape text, don't attept to do that again.
SwPaM aPaM(pNode->GetDoc()->GetNodes().GetEndOfContent()); if (!bEndedTextEdit)
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))
{ {
bFound = true; // If there are any shapes anchored to this node, search there.
break; 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; sal_Int32 aStart = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment