[Libreoffice-commits] core.git: Branch 'distro/vector/vector-5.4' - sw/CppunitTest_sw_unowriter.mk sw/qa sw/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Tue Dec 4 11:54:48 UTC 2018
sw/CppunitTest_sw_unowriter.mk | 1
sw/qa/extras/unowriter/data/selection-in-table-enum.odt |binary
sw/qa/extras/unowriter/unowriter.cxx | 48 ++++++++++++++++
sw/source/core/unocore/unoobj2.cxx | 8 ++
4 files changed, 57 insertions(+)
New commits:
commit bda3769274b95f9e7f68adfc9e374d6972e28abe
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Tue Dec 4 10:16:03 2018 +0100
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Tue Dec 4 12:45:26 2018 +0100
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.
Reviewed-on: https://gerrit.libreoffice.org/64509
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
Tested-by: Jenkins
(cherry picked from commit a4b67dbccb4f376ac3a75f8f602ea84b8c4d00ea)
Conflicts:
sw/qa/extras/unowriter/unowriter.cxx
Change-Id: Ibe2d00cfa75ed0c32b9c89d86cfae3b51d70ddc6
diff --git a/sw/CppunitTest_sw_unowriter.mk b/sw/CppunitTest_sw_unowriter.mk
index a51f4ac38000..486fd2056616 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
new file mode 100644
index 000000000000..bef9b0ea71e9
Binary files /dev/null and b/sw/qa/extras/unowriter/data/selection-in-table-enum.odt differ
diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx
index 59a045586423..de5cba1cd13d 100644
--- a/sw/qa/extras/unowriter/unowriter.cxx
+++ b/sw/qa/extras/unowriter/unowriter.cxx
@@ -9,15 +9,28 @@
#include <swmodeltestbase.hxx>
#include <com/sun/star/awt/FontSlant.hpp>
+#include <wrtsh.hxx>
+#include <ndtxt.hxx>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::text;
+
+namespace
+{
+char const DATA_DIRECTORY[] = "/sw/qa/extras/unowriter/data/";
+}
/// Test to assert UNO API call results of Writer.
class SwUnoWriter : public SwModelTestBase
{
public:
void testDefaultCharStyle();
+ void testSelectionInTableEnum();
CPPUNIT_TEST_SUITE(SwUnoWriter);
CPPUNIT_TEST(testDefaultCharStyle);
+ CPPUNIT_TEST(testSelectionInTableEnum);
CPPUNIT_TEST_SUITE_END();
};
@@ -47,6 +60,41 @@ void SwUnoWriter::testDefaultCharStyle()
getProperty<awt::FontSlant>(xCursorProps, "CharPosture"));
}
+void SwUnoWriter::testSelectionInTableEnum()
+{
+ load(DATA_DIRECTORY, "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_TEST_SUITE_REGISTRATION(SwUnoWriter);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx
index 288c3427d56d..7ffe23aad386 100644
--- a/sw/source/core/unocore/unoobj2.cxx
+++ b/sw/source/core/unocore/unoobj2.cxx
@@ -629,6 +629,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;
More information about the Libreoffice-commits
mailing list