sw/qa/uibase/shells/shells.cxx | 30 ++++++++++++++++++++++++++++++ sw/source/uibase/shells/textsh1.cxx | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-)
New commits: commit 83eae71c6c43dcb6bb50743f848088320d3d97a8 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri Jun 10 16:13:04 2022 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Jun 15 08:14:37 2022 +0200 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. (cherry picked from commit aa5824b2a6df99ef9d788a8d37bdfa77582375c8) Change-Id: Ib797ad164a3a36b4bbde4d686cde29adf6db96bf Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135822 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx index e1f5d048c018..4bde6eab7ac6 100644 --- a/sw/qa/uibase/shells/shells.cxx +++ b/sw/qa/uibase/shells/shells.cxx @@ -208,6 +208,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<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + xText->insertString(xCursor, "test", /*bAbsorb=*/false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->gotoEnd(/*bExpand=*/true); + uno::Reference<text::XTextContent> 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 ceba4f56522c..8d7c07e104ca 100644 --- a/sw/source/uibase/shells/textsh1.cxx +++ b/sw/source/uibase/shells/textsh1.cxx @@ -1894,7 +1894,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 ); }