From bd4663165b40d7bd0b3e1d685a6a22712656ba16 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 7 Aug 2019 17:43:50 +0200 Subject: sw: fix ViewCursor.PageStyleName for multi-page paragraphs In case the text frames of a text node span over multiple pages and the first page has a page style which has a follow page style, the page style under the cursor depends on not only the text node index, but also on the context index. Without this, the page style under the cursor will expose the first page's style name via the API, even if it's already on a follow page. Reviewed-on: https://gerrit.libreoffice.org/77128 Reviewed-by: Miklos Vajna Tested-by: Jenkins (cherry picked from commit 9a66b452ede70a25cd6fc8a72772a71b0ee7957a) Conflicts: sw/qa/extras/unowriter/unowriter.cxx Change-Id: I922e153750755317bda87441a88e9f53a6f348b7 --- sw/qa/extras/uiwriter/uiwriter.cxx | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'sw/qa/extras/uiwriter/uiwriter.cxx') diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index b1460ee5b1c9..c8a6d9619b63 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -220,6 +220,7 @@ public: void testLinesInSectionInTable(); void testParagraphOfTextRange(); void testLinesMoveBackwardsInSectionInTable(); + void testViewCursorPageStyle(); CPPUNIT_TEST_SUITE(SwUiWriterTest); CPPUNIT_TEST(testReplaceForward); @@ -343,6 +344,7 @@ public: #endif CPPUNIT_TEST(testLinesInSectionInTable); CPPUNIT_TEST(testParagraphOfTextRange); + CPPUNIT_TEST(testViewCursorPageStyle); CPPUNIT_TEST_SUITE_END(); private: @@ -4087,6 +4089,35 @@ void SwUiWriterTest::testTdf112160() CPPUNIT_ASSERT_EQUAL(OUString("Table1.D2"), pDoc->GetNodes()[nD2CellNode]->GetTextNode()->GetText()); } +void SwUiWriterTest::testViewCursorPageStyle() +{ + // Load a document with 2 pages, but a single paragraph. + createDoc("view-cursor-page-style.fodt"); + uno::Reference xModel(mxComponent, uno::UNO_QUERY); + CPPUNIT_ASSERT(xModel.is()); + uno::Reference xController(xModel->getCurrentController(), + uno::UNO_QUERY); + CPPUNIT_ASSERT(xController.is()); + uno::Reference xViewCursor(xController->getViewCursor(), uno::UNO_QUERY); + CPPUNIT_ASSERT(xViewCursor.is()); + + // Go to the first page, which has an explicit page style. + xViewCursor->jumpToPage(1); + OUString aActualPageStyleName = getProperty(xViewCursor, "PageStyleName"); + CPPUNIT_ASSERT_EQUAL(OUString("First Page"), aActualPageStyleName); + + // Go to the second page, which is still the first paragraph, but the page style is different, + // as the explicit 'First Page' page style has a next style defined (Standard). + xViewCursor->jumpToPage(2); + aActualPageStyleName = getProperty(xViewCursor, "PageStyleName"); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: Standard + // - Actual : First Page + // i.e. the cursor position was determined only based on the node index, ignoring the content + // index. + CPPUNIT_ASSERT_EQUAL(OUString("Standard"), aActualPageStyleName); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest); CPPUNIT_PLUGIN_IMPLEMENT(); -- cgit v1.2.3