diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2018-12-11 16:42:54 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2018-12-11 20:15:30 +0100 |
commit | 42dffe7b135c0680a8e20e4170a5f1176afc908e (patch) | |
tree | e824463eccd7a16ee6c091bada02b045c1377a33 /sw/qa | |
parent | e4c02a7bfe6f35afd359f6540b310437fd9a1d43 (diff) |
sw: fix paragraph enumeration going past a selected table
Writer has the internal invariant that if a text (non-table) selection
starts outside a table, it should end outside a table as well. This
means if you start your selection before a table and you try to select
till the end of the table, your selection will end at the start of the
next non-table node in fact.
This is especially confusing if you turn the selection into a paragraph
enumeration, where the last paragraph's 0 -> 0 character range is
"selected" (i.e. none of the paragraph content is selected) and still
the paragraph is included in the paragraph enumeration.
Special-case the "selection ending at para start after a table"
situation when it comes to turning this selection into a paragraph
enumeration to avoid the unexpected empty paragraph at the end.
Change-Id: I51432dee9e5d76971533c8059edab1cd9683434b
Reviewed-on: https://gerrit.libreoffice.org/64972
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw/qa')
-rw-r--r-- | sw/qa/extras/unowriter/unowriter.cxx | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx index 4bff617f62ef..8cba987a7c63 100644 --- a/sw/qa/extras/unowriter/unowriter.cxx +++ b/sw/qa/extras/unowriter/unowriter.cxx @@ -380,6 +380,44 @@ DECLARE_UNOAPI_TEST_FILE(testSelectionInTableEnum, "selection-in-table-enum.odt" CPPUNIT_ASSERT(!xEnum->hasMoreElements()); } +DECLARE_UNOAPI_TEST_FILE(testSelectionInTableEnumEnd, "selection-in-table-enum.odt") +{ + // Select from "Before" till the table end. + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell(); + CPPUNIT_ASSERT(pWrtShell); + pWrtShell->Down(/*bSelect=*/true); + + // 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()); + OUString aExpectedSelection + = "Before" SAL_NEWLINE_STRING "A1" SAL_NEWLINE_STRING "B1" SAL_NEWLINE_STRING + "C2" SAL_NEWLINE_STRING "A2" SAL_NEWLINE_STRING "B2" SAL_NEWLINE_STRING + "C2" SAL_NEWLINE_STRING; + CPPUNIT_ASSERT_EQUAL(aExpectedSelection, xSelection->getString()); + + // 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(); + // Before. + xEnum->nextElement(); + // Table. + xEnum->nextElement(); + // Without the accompanying fix in place, this test would have failed: i.e. + // the enumeration contained the paragraph after the table, but no part of + // that paragraph was part of the selection. + CPPUNIT_ASSERT(!xEnum->hasMoreElements()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |