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()
}
#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
}
......
......@@ -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;
......
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