From aa5824b2a6df99ef9d788a8d37bdfa77582375c8 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 10 Jun 2022 16:13:04 +0200 Subject: tdf#149509 sw content controls: reject page break insertion Similar to input fields, the intention is to keep the start and end of (inline) content controls within the same text node, so just disable the command in this context, as Word does. Change-Id: Ib797ad164a3a36b4bbde4d686cde29adf6db96bf Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135599 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- sw/qa/uibase/shells/shells.cxx | 30 ++++++++++++++++++++++++++++++ sw/source/uibase/shells/textsh1.cxx | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) (limited to 'sw') diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx index 902998bcdb1a..5a99b8e3c6bf 100644 --- a/sw/qa/uibase/shells/shells.cxx +++ b/sw/qa/uibase/shells/shells.cxx @@ -231,6 +231,36 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testBibliographyLocalCopyContextMenu) CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, eState); } +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testContentControlPageBreak) +{ + // Given a document with a content control and a cursor inside the content control: + SwDoc* pDoc = createSwDoc(); + uno::Reference xMSF(mxComponent, uno::UNO_QUERY); + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xText = xTextDocument->getText(); + uno::Reference xCursor = xText->createTextCursor(); + xText->insertString(xCursor, "test", /*bAbsorb=*/false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->gotoEnd(/*bExpand=*/true); + uno::Reference xContentControl( + xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY); + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->SttEndDoc(/*bStt=*/true); + pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, /*bBasicCall=*/false); + + // When trying to insert a page break: + dispatchCommand(mxComponent, ".uno:InsertPagebreak", {}); + + // Then make sure that the document still has a single page: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 2 + // i.e. inline content control had its start and end in different text nodes, which is not + // allowed. + CPPUNIT_ASSERT_EQUAL(1, getPages()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx index e74e47a98e39..4531da1486f3 100644 --- a/sw/source/uibase/shells/textsh1.cxx +++ b/sw/source/uibase/shells/textsh1.cxx @@ -1896,7 +1896,7 @@ void SwTextShell::GetState( SfxItemSet &rSet ) case FN_INSERT_BREAK_DLG: case FN_INSERT_COLUMN_BREAK: case FN_INSERT_PAGEBREAK: - if( rSh.CursorInsideInputField() ) + if( rSh.CursorInsideInputField() || rSh.CursorInsideContentControl() ) { rSet.DisableItem( nWhich ); } -- cgit