cool#16002 sw markdown paste: avoid unwanted empty paragraph at the end
Open the bugdoc, navigate to the end of the first bulleted paragraph, paste the 2 bullets from markdown, there is an empty bullet between the end of the pasted content and the start of the content after the paste position. What happens is that paste finishes with an empty text node at the end of the document, which is handy in general, in case there is content after the bullets for the normal import case. Fix the problem by checking for this "empty paragraph before the insert position" situation in MarkdownReader::Read(), and by joining the problematic empty text node with the previous node in the paste case. This is the opposite of the problem in commit f6f13d042b1e176ba1cb13cea37d5e5c2add9a9f (cool#16002 sw markdown import: avoid unwanted list join at start, 2026-07-13), where two paragraphs were joined together and that wasn't wanted. Signed-off-by: Miklos Vajna <vmiklos@collabora.com> Change-Id: I711f1eb520854081e579f77dc98606592672720a Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/6786 Tested-by: Jenkins CPCI <releng@collaboraoffice.com> Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com> (cherry picked from commit ccd06e3822f4a828be7467bf7e338b717d6facda) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/208343 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org> Tested-by: Jenkins
This commit is contained in:
committed by
Xisco Fauli
parent
b4a4f4141e
commit
dae573c60a
@@ -1068,6 +1068,15 @@ CPPUNIT_TEST_FIXTURE(Test, testListPaste)
|
||||
// i.e. pasting a list item at the end of a list item joined the two.
|
||||
CPPUNIT_ASSERT_EQUAL(u"List A"_ustr, getParagraph(2)->getString());
|
||||
CPPUNIT_ASSERT_EQUAL(u"List 1"_ustr, getParagraph(3)->getString());
|
||||
|
||||
// And make sure the pasted list doesn't leave a trailing empty bullet
|
||||
// between "List 2" and the pre-existing "List B" list item:
|
||||
// Without the accompanying fix in place, this test would have failed with:
|
||||
// - Expected: List 2
|
||||
// - Actual :
|
||||
// i.e. paragraph 4 was an empty.
|
||||
CPPUNIT_ASSERT_EQUAL(u"List 2"_ustr, getParagraph(4)->getString());
|
||||
CPPUNIT_ASSERT_EQUAL(u"List B"_ustr, getParagraph(5)->getString());
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_FIXTURE(Test, testCTLPaste)
|
||||
|
||||
@@ -889,6 +889,19 @@ ErrCodeMsg MarkdownReader::Read(SwDoc& rDoc, const OUString& rBaseURL, SwPaM& rP
|
||||
|
||||
if (m_bInsertMode)
|
||||
{
|
||||
if (aPasteInfo.m_bStartAtEndOfPara)
|
||||
{
|
||||
// If the paste created an empty paragraph at the end, join that empty node with the
|
||||
// previous one here.
|
||||
SwNodeIndex aLast(*aPasteInfo.m_pSttNdIdx2, -1);
|
||||
if (aLast.GetIndex() > aPasteInfo.m_pSttNdIdx->GetIndex() + 1)
|
||||
{
|
||||
SwTextNode* pLast = aLast.GetNode().GetTextNode();
|
||||
if (pLast && pLast->GetText().isEmpty())
|
||||
pLast->JoinPrev();
|
||||
}
|
||||
}
|
||||
|
||||
EndPaste(aPasteInfo);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user