diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2018-12-04 10:16:03 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2018-12-04 12:23:47 +0100 |
commit | a4b67dbccb4f376ac3a75f8f602ea84b8c4d00ea (patch) | |
tree | 560d882028832e9ebfdd1792781bf71aeb7a33bc | |
parent | 607b80ca3cddc239a35580470944a438ce144fc8 (diff) |
sw: fix paragraph enumeration going past selection end
SwCursor::MovePara() may move the uno cursor past the end of the
selection range, check for this explicitly.
In practice this makes sure that in case a 1-paragraph cell text is
selected, we never jump to the next cell for a selection created from
the previous cell.
Change-Id: Ibe2d00cfa75ed0c32b9c89d86cfae3b51d70ddc6
Reviewed-on: https://gerrit.libreoffice.org/64509
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
-rw-r--r-- | sw/CppunitTest_sw_unowriter.mk | 1 | ||||
-rw-r--r-- | sw/qa/extras/unowriter/data/selection-in-table-enum.odt | bin | 0 -> 8941 bytes | |||
-rw-r--r-- | sw/qa/extras/unowriter/unowriter.cxx | 35 | ||||
-rw-r--r-- | sw/source/core/unocore/unoobj2.cxx | 8 |
4 files changed, 44 insertions, 0 deletions
diff --git a/sw/CppunitTest_sw_unowriter.mk b/sw/CppunitTest_sw_unowriter.mk index b4b27bd402a4..726e364f4238 100644 --- a/sw/CppunitTest_sw_unowriter.mk +++ b/sw/CppunitTest_sw_unowriter.mk @@ -44,6 +44,7 @@ $(eval $(call gb_CppunitTest_use_externals,sw_unowriter,\ $(eval $(call gb_CppunitTest_set_include,sw_unowriter,\ -I$(SRCDIR)/sw/inc \ -I$(SRCDIR)/sw/source/core/inc \ + -I$(SRCDIR)/sw/source/uibase/inc \ -I$(SRCDIR)/sw/qa/extras/inc \ $$(INCLUDE) \ )) diff --git a/sw/qa/extras/unowriter/data/selection-in-table-enum.odt b/sw/qa/extras/unowriter/data/selection-in-table-enum.odt Binary files differnew file mode 100644 index 000000000000..bef9b0ea71e9 --- /dev/null +++ b/sw/qa/extras/unowriter/data/selection-in-table-enum.odt diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx index 96e29c303319..4bff617f62ef 100644 --- a/sw/qa/extras/unowriter/unowriter.cxx +++ b/sw/qa/extras/unowriter/unowriter.cxx @@ -14,6 +14,8 @@ #include <com/sun/star/text/XAutoTextGroup.hpp> #include <com/sun/star/rdf/URI.hpp> #include <com/sun/star/rdf/URIs.hpp> +#include <wrtsh.hxx> +#include <ndtxt.hxx> using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -345,6 +347,39 @@ DECLARE_UNOAPI_TEST(testSetPagePrintSettings) CPPUNIT_ASSERT_EQUAL(true, aMap.getValue("IsLandscape").get<bool>()); } +DECLARE_UNOAPI_TEST_FILE(testSelectionInTableEnum, "selection-in-table-enum.odt") +{ + // Select the A1 cell's text. + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell(); + CPPUNIT_ASSERT(pWrtShell); + pWrtShell->Down(/*bSelect=*/false); + pWrtShell->EndPara(/*bSelect=*/true); + CPPUNIT_ASSERT_EQUAL(OUString("A1"), + pWrtShell->GetCursor()->GetNode().GetTextNode()->GetText()); + + // Access the selection. + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + CPPUNIT_ASSERT(xModel.is()); + uno::Reference<container::XIndexAccess> xSelections(xModel->getCurrentSelection(), + uno::UNO_QUERY); + CPPUNIT_ASSERT(xSelections.is()); + uno::Reference<text::XTextRange> xSelection(xSelections->getByIndex(0), uno::UNO_QUERY); + CPPUNIT_ASSERT(xSelection.is()); + + // Enumerate paragraphs in the selection. + uno::Reference<container::XEnumerationAccess> xCursor( + xSelection->getText()->createTextCursorByRange(xSelection), uno::UNO_QUERY); + CPPUNIT_ASSERT(xCursor.is()); + uno::Reference<container::XEnumeration> xEnum = xCursor->createEnumeration(); + xEnum->nextElement(); + // Without the accompanying fix in place, this test would have failed: i.e. + // the enumeration contained a second paragraph, even if the cell has only + // one paragraph. + CPPUNIT_ASSERT(!xEnum->hasMoreElements()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx index b2ddbe1e1997..98a6b079a69c 100644 --- a/sw/source/core/unocore/unoobj2.cxx +++ b/sw/source/core/unocore/unoobj2.cxx @@ -631,6 +631,14 @@ SwXParagraphEnumerationImpl::NextElement_Impl() (rUnoCursor.MovePara(GoNextPara, fnParaStart) && lcl_CursorIsInSection( &rUnoCursor, m_pOwnStartNode )))) { + if (m_eCursorType == CursorType::Selection || m_eCursorType == CursorType::SelectionInTable) + { + // This is a selection, check if the cursor would go past the end + // of the selection. + if (rUnoCursor.Start()->nNode.GetIndex() > m_nEndIndex) + return nullptr; + } + SwPosition* pStart = rUnoCursor.Start(); const sal_Int32 nFirstContent = (m_bFirstParagraph) ? m_nFirstParaStart : -1; |