DOCX import: fix unexpected page break on autotext insert at end of doc

The problem was that the page style was set on the first paragraph,
which means a page break on the UI. So if you used a multi-paragraph
autotext twice (insert autotext, press enter, insert autotext again)
then you ended up with 2 pages instead of just 1.

Fix the problem by tracking when we are in autotext import mode, and
similar to pasting, don't set the page style in autotext import mode.

Change-Id: I4fc551b3c1b999687eb80242e261f186fd1b6f13
Reviewed-on: https://gerrit.libreoffice.org/69214
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
This commit is contained in:
Miklos Vajna 2019-03-13 17:51:07 +01:00
parent 17b25fd3df
commit adcf656bb5
4 changed files with 21 additions and 5 deletions

View file

@ -1024,7 +1024,15 @@ void SwUiWriterTest::testDOCXAutoTextMultiple()
// first line
SwNode& rNode = aStart.GetNode();
CPPUNIT_ASSERT_EQUAL(OUString("Another "), rNode.GetTextNode()->GetText());
CPPUNIT_ASSERT(rNode.IsTextNode());
SwTextNode& rTextNode = *rNode.GetTextNode();
CPPUNIT_ASSERT_EQUAL(OUString("Another "), rTextNode.GetText());
// Make sure that autotext does not set a custom page style, leading to an unexpected page break
// on insertion.
// Without the accompanying fix in place, this test would have failed: the text node had an
// attribute set containing a page style item.
CPPUNIT_ASSERT(!rTextNode.HasSwAttrSet() || !rTextNode.GetSwAttrSet().HasItem(RES_PAGEDESC));
// last line
SwNodeIndex aLast(*aDocEnd.GetNode().EndOfSectionNode(), -1);

View file

@ -239,6 +239,7 @@ DomainMapper_Impl::DomainMapper_Impl(
m_aSmartTagHandler(m_xComponentContext, m_xTextDocument),
m_xInsertTextRange(rMediaDesc.getUnpackedValueOrDefault("TextInsertModeRange", uno::Reference<text::XTextRange>())),
m_bIsNewDoc(!rMediaDesc.getUnpackedValueOrDefault("InsertMode", false)),
m_bIsReadGlossaries(rMediaDesc.getUnpackedValueOrDefault("ReadGlossaries", false)),
m_bInTableStyleRunProps(false),
m_nTableDepth(0),
m_nTableCellDepth(0),

View file

@ -548,6 +548,7 @@ public:
css::uno::Reference<css::text::XTextRange> m_xInsertTextRange;
private:
bool const m_bIsNewDoc;
bool const m_bIsReadGlossaries;
public:
DomainMapper_Impl(
DomainMapper& rDMapper,
@ -916,6 +917,9 @@ public:
/// If we're importing into a new document, or just pasting to an existing one.
bool IsNewDoc() { return m_bIsNewDoc;}
/// If we're importing autotext.
bool IsReadGlossaries() { return m_bIsReadGlossaries;}
/// If we're inside <w:rPr>, inside <w:style w:type="table">
bool m_bInTableStyleRunProps;

View file

@ -1642,10 +1642,13 @@ void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )
if ( xRangeProperties.is() && rDM_Impl.IsNewDoc() )
{
xRangeProperties->setPropertyValue(
getPropertyName( PROP_PAGE_DESC_NAME ),
uno::makeAny( m_bTitlePage ? m_sFirstPageStyleName
: m_sFollowPageStyleName ) );
// Avoid setting page style in case of autotext: so inserting the autotext at the
// end of the document does not introduce an unwanted page break.
if (!rDM_Impl.IsReadGlossaries())
xRangeProperties->setPropertyValue(
getPropertyName( PROP_PAGE_DESC_NAME ),
uno::makeAny( m_bTitlePage ? m_sFirstPageStyleName
: m_sFollowPageStyleName ) );
if (0 <= m_nPageNumber)
{