diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-06-10 16:13:04 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-06-13 08:09:51 +0200 |
commit | aa5824b2a6df99ef9d788a8d37bdfa77582375c8 (patch) | |
tree | 32e4e66a2426fdb3e08ff70ac0af6ad5cd178549 /sw | |
parent | c321498f915f4e8b3f4853232860ce040ab48e46 (diff) |
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 <vmiklos@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/uibase/shells/shells.cxx | 30 | ||||
-rw-r--r-- | sw/source/uibase/shells/textsh1.cxx | 2 |
2 files changed, 31 insertions, 1 deletions
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<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 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 ); } |