From 9b7542b0928f81b36365b13228a402e8cd64e8cd Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Fri, 31 Oct 2014 22:06:40 +0100 Subject: sw: fix insertion of hyperlink inside hyperlink... ... when either the start or the end position of the new hint is equal to an existing hint. There is not just 1 case here but 3 different ones; don't attempt to insert hints with start > end. Change-Id: I39cf8a352f67d77b56b0d01de5872f4d341f6bdd --- .../complex/writer/TextPortionEnumerationTest.java | 23 +++++++++++++++++ sw/source/core/txtnode/thints.cxx | 30 ++++++++++++++-------- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/sw/qa/complex/writer/TextPortionEnumerationTest.java b/sw/qa/complex/writer/TextPortionEnumerationTest.java index 4e62d33d3bc0..b793b9ae3747 100644 --- a/sw/qa/complex/writer/TextPortionEnumerationTest.java +++ b/sw/qa/complex/writer/TextPortionEnumerationTest.java @@ -2051,6 +2051,29 @@ public class TextPortionEnumerationTest // this one gets eaten, but we still need to test inserting it (#i106930#) // .appendChild( url6.dup().appendChild( new TextNode("") ) ) .appendChild( new TextNode("89") ); + // inside (left-edge) + TreeNode url7 = new HyperlinkNode( mkName("url") ); + inserter.insertRange( new Range(0, 1, url7) ); + root = new TreeNode() + .appendChild( url7.dup().appendChild( new TextNode("1") ) ) + .appendChild( url2.dup().appendChild( new TextNode("2") ) ) + .appendChild( url1.dup().appendChild( new TextNode("3") ) ) + .appendChild( url4.dup().appendChild( new TextNode("4") ) ) + .appendChild( url5.dup().appendChild( new TextNode("56") ) ) + .appendChild( url4.dup().appendChild( new TextNode("7") ) ) + .appendChild( new TextNode("89") ); + // inside (right-edge) + TreeNode url8 = new HyperlinkNode( mkName("url") ); + inserter.insertRange( new Range(5, 6, url8) ); + root = new TreeNode() + .appendChild( url7.dup().appendChild( new TextNode("1") ) ) + .appendChild( url2.dup().appendChild( new TextNode("2") ) ) + .appendChild( url1.dup().appendChild( new TextNode("3") ) ) + .appendChild( url4.dup().appendChild( new TextNode("4") ) ) + .appendChild( url5.dup().appendChild( new TextNode("5") ) ) + .appendChild( url8.dup().appendChild( new TextNode("6") ) ) + .appendChild( url4.dup().appendChild( new TextNode("7") ) ) + .appendChild( new TextNode("89") ); doTest(root, false); } diff --git a/sw/source/core/txtnode/thints.cxx b/sw/source/core/txtnode/thints.cxx index c29f87ed597a..1494553a63c4 100644 --- a/sw/source/core/txtnode/thints.cxx +++ b/sw/source/core/txtnode/thints.cxx @@ -550,23 +550,31 @@ SwpHints::TryInsertNesting( SwTxtNode & rNode, SwTxtAttrNesting & rNewHint ) } else { - assert((nOtherStart < nNewStart) && (nNewEnd < nOtherEnd)); + assert((nOtherStart < nNewStart) || (nNewEnd < nOtherEnd)); // scenario: there is a RUBY, and contained within that a META; // now a RUBY is inserted within the META => the exising RUBY is split: // here it is not possible to simply insert the left/right fragment // of the existing RUBY because they overlap with the META! Delete( *itOther ); // this also does NoteInHistory! - *(*itOther)->GetEnd() = nNewStart; - bool bSuccess( TryInsertNesting(rNode, **itOther) ); - OSL_ENSURE(bSuccess, "recursive call 1 failed?"); - SwTxtAttrNesting * const pOtherRight( - MakeTxtAttrNesting( - rNode, **itOther, nNewEnd, nOtherEnd ) ); - bSuccess = TryInsertNesting(rNode, *pOtherRight); - OSL_ENSURE(bSuccess, "recursive call 2 failed?"); - (void)bSuccess; + if (nNewEnd < nOtherEnd) + { + SwTxtAttrNesting * const pOtherRight( + MakeTxtAttrNesting( + rNode, **itOther, nNewEnd, nOtherEnd ) ); + bool const bSuccess( TryInsertNesting(rNode, *pOtherRight) ); + SAL_WARN_IF(!bSuccess, "sw.core", "recursive call 1 failed?"); + } + if (nOtherStart < nNewStart) + { + *(*itOther)->GetEnd() = nNewStart; + bool const bSuccess( TryInsertNesting(rNode, **itOther) ); + SAL_WARN_IF(!bSuccess, "sw.core", "recursive call 2 failed?"); + } + else + { + rNode.DestroyAttr(*itOther); + } } - } return true; -- cgit