Related: cool#15535 sw markdown import: use matching paragraph formatting
Open the bugdoc, position the cursor before "A", paste the markdown snippet: the content is OK, the bullet size is OK, but the paragraph style & margins of the new content is different to the existing content. Given that markdown has no way to specify a paragraph style for normal (non-heading) text and also no way to specify paragraph margins, it's reasonable to expect these are just copied from the paste insertion point for consistency. Fix this by: 1) Putting the end of Reader::StartPaste() back to SwRTFReader::Read(), so the RTF paste behavior is unchanged, but we don't reset the paragraph style in Reader::StartPaste() for markdown 2) Extending SwMarkdownParser::CallParser() to not reset the paragraph style in the paste case before calling md_parse() 3) Extending SwMarkdownParser::EndNumberedBulletListItem() to not touch paragraph margins when pasting. The behavior for normal (non-paste) markdown import is unchanged. Change-Id: I57e9f329f48bcd9a6e1388bb635c7a2a9489aecf Reviewed-on: https://gerrit.collaboraoffice.com/c/core/+/1238 Tested-by: Jenkins CPCI <releng@collaboraoffice.com> Tested-by: Caolán McNamara <caolan.mcnamara@collabora.com> Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com> (cherry picked from commit 21c6c0139ceb307525fb0cc05c7a547b8e07d16f) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204397 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
This commit is contained in:
committed by
Xisco Fauli
parent
de35dc3a6a
commit
8f5d83abd4
@@ -1032,6 +1032,21 @@ CPPUNIT_TEST_FIXTURE(Test, testPaste)
|
||||
// - Actual : WWNum2
|
||||
// i.e. List 1 & 2 had a non-named list style instead of being consistent with "A".
|
||||
CPPUNIT_ASSERT_EQUAL(aList2Style, aAStyle);
|
||||
|
||||
// Also check that paragraph style and margins are preserved from the insertion point:
|
||||
OUString aList2ParaStyle = getProperty<OUString>(getParagraph(3), u"ParaStyleName"_ustr);
|
||||
OUString aAParaStyle = getProperty<OUString>(getParagraph(4), u"ParaStyleName"_ustr);
|
||||
// Without the accompanying fix in place, this test would have failed with:
|
||||
// - Expected: Standard
|
||||
// - Actual : Text body
|
||||
// i.e. the pasted paragraphs lost paragraph style from the insertion point.
|
||||
CPPUNIT_ASSERT_EQUAL(aAParaStyle, aList2ParaStyle);
|
||||
sal_Int32 aList2Top = getProperty<sal_Int32>(getParagraph(3), u"ParaTopMargin"_ustr);
|
||||
sal_Int32 aATop = getProperty<sal_Int32>(getParagraph(4), u"ParaTopMargin"_ustr);
|
||||
CPPUNIT_ASSERT_EQUAL(aATop, aList2Top);
|
||||
sal_Int32 aList2Bottom = getProperty<sal_Int32>(getParagraph(3), u"ParaBottomMargin"_ustr);
|
||||
sal_Int32 aABottom = getProperty<sal_Int32>(getParagraph(4), u"ParaBottomMargin"_ustr);
|
||||
CPPUNIT_ASSERT_EQUAL(aABottom, aList2Bottom);
|
||||
}
|
||||
|
||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||
|
||||
@@ -673,9 +673,6 @@ void Reader::StartPaste(SwPasteInfo& rPasteInfo)
|
||||
|
||||
// Step 4: Insert all content into the new node
|
||||
rPasteInfo.m_rPam.Move(fnMoveBackward);
|
||||
rPasteInfo.m_rDoc.SetTextFormatColl(rPasteInfo.m_rPam, rPasteInfo.m_rDoc.getIDocumentStylePoolAccess().GetTextCollFromPool(
|
||||
SwPoolFormatId::COLL_STANDARD, false));
|
||||
|
||||
}
|
||||
|
||||
void Reader::EndPaste(SwPasteInfo& rPasteInfo)
|
||||
|
||||
@@ -569,7 +569,15 @@ void SwMarkdownParser::StartNumberedBulletListItem(MD_BLOCK_LI_DETAIL aDetail)
|
||||
void SwMarkdownParser::EndNumberedBulletListItem()
|
||||
{
|
||||
if (m_pPam->GetPoint()->GetContentIndex())
|
||||
AppendTextNode(AM_SPACE);
|
||||
{
|
||||
SwMdAppendMode eMode = AM_SPACE;
|
||||
if (!m_bNewDoc)
|
||||
{
|
||||
// Don't touch paragraph margins when pasting.
|
||||
eMode = AM_NORMAL;
|
||||
}
|
||||
AppendTextNode(eMode);
|
||||
}
|
||||
}
|
||||
|
||||
void SwMarkdownParser::BeginHtmlBlock()
|
||||
@@ -921,7 +929,11 @@ ErrCode SwMarkdownParser::CallParser()
|
||||
|
||||
SwTextFormatColl* pColl
|
||||
= m_xDoc->getIDocumentStylePoolAccess().GetTextCollFromPool(SwPoolFormatId::COLL_TEXT);
|
||||
m_xDoc->SetTextFormatColl(*m_pPam, pColl);
|
||||
if (m_bNewDoc)
|
||||
{
|
||||
// Don't touch the paragraph style when pasting.
|
||||
m_xDoc->SetTextFormatColl(*m_pPam, pColl);
|
||||
}
|
||||
|
||||
ErrCode nRet;
|
||||
|
||||
|
||||
@@ -66,6 +66,9 @@ ErrCodeMsg SwRTFReader::Read(SwDoc& rDoc, const OUString& /*rBaseURL*/, SwPaM& r
|
||||
|
||||
SwPasteInfo aPasteInfo(rDoc, rPam);
|
||||
StartPaste(aPasteInfo);
|
||||
// Reset paragraph style to Body Text.
|
||||
rDoc.SetTextFormatColl(rPam, rDoc.getIDocumentStylePoolAccess().GetTextCollFromPool(
|
||||
SwPoolFormatId::COLL_STANDARD, false));
|
||||
|
||||
auto ret = ERRCODE_NONE;
|
||||
SwDocShell* pDocShell(rDoc.GetDocShell());
|
||||
|
||||
Reference in New Issue
Block a user