From cd4976988cf3acb4f1a23f1df7fcc2bfec0f3da0 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Thu, 15 Oct 2015 15:20:23 +0200 Subject: sd tiled rendering: let find-all at least select the first match physically The LOK API can describe a multi-selection, so find-all can signal all matches, editeng can have a single selection only. Instead of having no selections after a find-all, select the first match, so e.g. copy works. Change-Id: I0eab2565916f0c3cce5d77279c0d927ad4b7054c --- sd/qa/unit/tiledrendering/data/search-all.odp | Bin 0 -> 10744 bytes sd/qa/unit/tiledrendering/tiledrendering.cxx | 19 +++++++++++++++++-- sd/source/ui/view/Outliner.cxx | 13 ++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 sd/qa/unit/tiledrendering/data/search-all.odp diff --git a/sd/qa/unit/tiledrendering/data/search-all.odp b/sd/qa/unit/tiledrendering/data/search-all.odp new file mode 100644 index 000000000000..cb3cb31cf5c7 Binary files /dev/null and b/sd/qa/unit/tiledrendering/data/search-all.odp differ diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index 4a5c81b7498a..89a2bf11b228 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -51,6 +52,7 @@ public: void testSetGraphicSelection(); void testResetSelection(); void testSearch(); + void testSearchAll(); #endif CPPUNIT_TEST_SUITE(SdTiledRenderingTest); @@ -63,6 +65,7 @@ public: CPPUNIT_TEST(testSetGraphicSelection); CPPUNIT_TEST(testResetSelection); CPPUNIT_TEST(testSearch); + CPPUNIT_TEST(testSearchAll); #endif CPPUNIT_TEST_SUITE_END(); @@ -371,12 +374,13 @@ void SdTiledRenderingTest::testResetSelection() CPPUNIT_ASSERT(!pView->GetTextEditObject()); } -static void lcl_search(const OUString& rKey) +static void lcl_search(const OUString& rKey, bool bFindAll = false) { uno::Sequence aPropertyValues(comphelper::InitPropertySequence( { {"SearchItem.SearchString", uno::makeAny(rKey)}, - {"SearchItem.Backward", uno::makeAny(false)} + {"SearchItem.Backward", uno::makeAny(false)}, + {"SearchItem.Command", uno::makeAny(static_cast(bFindAll ? SvxSearchCmd::FIND_ALL : SvxSearchCmd::FIND))}, })); comphelper::dispatchCommand(".uno:ExecuteSearch", aPropertyValues); } @@ -414,6 +418,17 @@ void SdTiledRenderingTest::testSearch() CPPUNIT_ASSERT_EQUAL(false, m_bFound); } +void SdTiledRenderingTest::testSearchAll() +{ + SdXImpressDocument* pXImpressDocument = createDoc("search-all.odp"); + + lcl_search("match", /*bFindAll=*/true); + + OString aUsedFormat; + // This was empty: find-all did not highlight the first match. + CPPUNIT_ASSERT_EQUAL(OString("match"), pXImpressDocument->getTextSelection("text/plain;charset=utf-8", aUsedFormat)); +} + #endif CPPUNIT_TEST_SUITE_REGISTRATION(SdTiledRenderingTest); diff --git a/sd/source/ui/view/Outliner.cxx b/sd/source/ui/view/Outliner.cxx index 263ea6f92d5e..8c79ac4048ac 100644 --- a/sd/source/ui/view/Outliner.cxx +++ b/sd/source/ui/view/Outliner.cxx @@ -593,6 +593,7 @@ void Outliner::Initialize (bool bDirectionIsForward) bool Outliner::SearchAndReplaceAll() { + bool bRet = true; // Save the current position to be restored after having replaced all // matches. RememberStartPosition (); @@ -630,6 +631,16 @@ bool Outliner::SearchAndReplaceAll() do { bFoundMatch = ! SearchAndReplaceOnce(&aSelections); + if (mpSearchItem->GetCommand() == SvxSearchCmd::FIND_ALL && pViewShell->GetDoc()->isTiledRendering() && bFoundMatch && aSelections.size() == 1) + { + // Without this, RememberStartPosition() will think it already has a remembered position. + mnStartPageIndex = (sal_uInt16)-1; + + RememberStartPosition(); + + // So when RestoreStartPosition() restores the first match, then spellchecker doesn't kill the selection. + bRet = false; + } } while (bFoundMatch); @@ -658,7 +669,7 @@ bool Outliner::SearchAndReplaceAll() RestoreStartPosition (); mnStartPageIndex = (sal_uInt16)-1; - return true; + return bRet; } bool Outliner::SearchAndReplaceOnce(std::vector* pSelections) -- cgit v1.2.3