Kaydet (Commit) 6126de03 authored tarafından Serge Krot's avatar Serge Krot Kaydeden (comit) Thorsten Behrens

sw: fix inconsistent bookmark behavior around at-char/as-char anchored frames

Added unit test for Added fix for
   Change-Id: Ic1f173c85d3824afabb5b7ebf3a8594311eb9007

Change-Id: I38444587d00b96d52ff725dc7c5852e057bc6bd9
Reviewed-on: https://gerrit.libreoffice.org/59828
Tested-by: Jenkins
Reviewed-by: 's avatarThorsten Behrens <Thorsten.Behrens@CIB.de>
üst 22d2b332
......@@ -347,6 +347,7 @@ public:
void testTdf117225();
void testTdf91801();
void testTdf51223();
void testInconsistentBookmark();
CPPUNIT_TEST_SUITE(SwUiWriterTest);
CPPUNIT_TEST(testReplaceForward);
......@@ -545,6 +546,7 @@ public:
CPPUNIT_TEST(testTdf117225);
CPPUNIT_TEST(testTdf91801);
CPPUNIT_TEST(testTdf51223);
CPPUNIT_TEST(testInconsistentBookmark);
CPPUNIT_TEST_SUITE_END();
private:
......@@ -6472,6 +6474,66 @@ void SwUiWriterTest::testFontEmbedding()
#endif
}
// Unit test for fix inconsistent bookmark behavior around at-char/as-char anchored frames
//
// We have a placeholder character in the sw doc model for as-char anchored frames,
// so it's possible to have a bookmark before/after the frame or a non-collapsed bookmark
// which covers the frame. The same is not true for at-char anchored frames,
// where the anchor points to a doc model position, but there is no placeholder character.
// If a bookmark is created covering the start and end of the anchor of the frame,
// internally we create a collapsed bookmark which has the same position as the anchor of the frame.
// When this doc model is handled by SwXParagraph::createEnumeration(),
// first the frame and then the bookmark is appended to the text portion enumeration,
// so your bookmark around the frame is turned into a collapsed bookmark after the frame.
// (The same happens when we roundtrip an ODT document representing this doc model.)
//
// Fix the problem by inserting collapsed bookmarks with affected anchor positions
// (same position is the anchor for an at-char frame) into the enumeration in two stages:
// first the start of them before frames and then the end of them + other bookmarks.
// This way UNO API users get their non-collapsed bookmarks around at-char anchored frames,
// similar to as-char ones.
void SwUiWriterTest::testInconsistentBookmark()
{
// create test document with text and bookmark
{
SwDoc* pDoc(createDoc("testInconsistentBookmark.ott"));
IDocumentMarkAccess& rIDMA(*pDoc->getIDocumentMarkAccess());
SwNodeIndex aIdx(pDoc->GetNodes().GetEndOfContent(), -1);
SwCursor aPaM(SwPosition(aIdx), nullptr);
aPaM.SetMark();
aPaM.MovePara(GoCurrPara, fnParaStart);
aPaM.MovePara(GoCurrPara, fnParaEnd);
rIDMA.makeMark(aPaM, "Mark", IDocumentMarkAccess::MarkType::BOOKMARK,
::sw::mark::InsertMode::New);
aPaM.Exchange();
aPaM.DeleteMark();
}
// save document and verify the bookmark scoup
{
// save document
utl::TempFile aTempFile;
save("writer8", aTempFile);
// load only content.xml
if (xmlDocPtr pXmlDoc = parseExportInternal(aTempFile.GetURL(), "content.xml"))
{
const OString aPath("/office:document-content/office:body/office:text/text:p");
const OUString aTagBookmarkStart("bookmark-start");
const OUString aTagControl("control");
const OUString aTagBookmarkEnd("bookmark-end");
const int pos1 = getXPathPosition(pXmlDoc, aPath, aTagBookmarkStart);
const int pos2 = getXPathPosition(pXmlDoc, aPath, aTagControl);
const int pos3 = getXPathPosition(pXmlDoc, aPath, aTagBookmarkEnd);
CPPUNIT_ASSERT_GREATER(pos1, pos2);
CPPUNIT_ASSERT_GREATER(pos2, pos3);
}
}
}
CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
CPPUNIT_PLUGIN_IMPLEMENT();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment