[Libreoffice-commits] core.git: 2 commits - sw/source

Michael Stahl mstahl at redhat.com
Mon May 11 15:19:28 PDT 2015


 sw/source/core/unocore/unotext.cxx |   47 +++++++++++++++++++++----------------
 1 file changed, 27 insertions(+), 20 deletions(-)

New commits:
commit ac55ac11f66c9b8b44dc8281d6236d9e6d68ddd1
Author: Michael Stahl <mstahl at redhat.com>
Date:   Mon May 11 23:54:23 2015 +0200

    sw: remove the rLastPaM parameter for SwXText::Impl::ConvertCell()
    
    It is redundant now with pLastCell, and the code updating it looks
    highly questionable.
    
    Furthermore ConvertCell() has a post-condition that the last paragraph
    in the cell is selected until the end (enforced by split if necessary).
    
    Change-Id: I4351dcd76089eb610808ee847809b58e59048b12

diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx
index 6f124fa..0f71af2 100644
--- a/sw/source/core/unocore/unotext.cxx
+++ b/sw/source/core/unocore/unotext.cxx
@@ -114,7 +114,6 @@ public:
             const uno::Sequence< uno::Reference< text::XTextRange > > & rCell,
             ::std::vector<SwNodeRange> & rRowNodes,
             ::std::unique_ptr< SwPaM > & rpFirstPaM,
-            SwPaM & rLastPaM,
             SwNodeRange *const pLastCell,
             bool & rbExcept);
 
@@ -1821,7 +1820,6 @@ void SwXText::Impl::ConvertCell(
     const uno::Sequence< uno::Reference< text::XTextRange > > & rCell,
     ::std::vector<SwNodeRange> & rRowNodes,
     ::std::unique_ptr< SwPaM > & rpFirstPaM,
-    SwPaM & rLastPaM,
     SwNodeRange *const pLastCell,
     bool & rbExcept)
 {
@@ -1918,20 +1916,18 @@ void SwXText::Impl::ConvertCell(
     else
     {
         // check the predecessor
-        const sal_uLong nLastNodeIndex = rLastPaM.End()->nNode.GetIndex();
         const sal_uLong nStartCellNodeIndex =
             aStartCellPam.Start()->nNode.GetIndex();
-        const sal_uLong nLastNodeEndIndex = rLastPaM.End()->nNode.GetIndex();
-        if (nLastNodeIndex == nStartCellNodeIndex)
+        const sal_uLong nLastNodeEndIndex = pLastCell->aEnd.GetIndex();
+        if (nLastNodeEndIndex == nStartCellNodeIndex)
         {
             // same node as predecessor then equal nContent?
-            if (rLastPaM.End()->nContent != aStartCellPam.Start()->nContent)
+            if (0 != aStartCellPam.Start()->nContent.GetIndex())
             {
                 rbExcept = true;
             }
             else
             {
-                // note: this may modify rLastPaM too!
                 m_pDoc->getIDocumentContentOperations().SplitNode(*aStartCellPam.Start(), false);
                 sal_uLong const nNewIndex(aStartCellPam.Start()->nNode.GetIndex());
                 if (nNewIndex != nStartCellNodeIndex)
@@ -1979,17 +1975,7 @@ void SwXText::Impl::ConvertCell(
             aEndCellPam.GetNode().GetTxtNode()->Len();
     }
 
-    *rLastPaM.GetPoint() = *aEndCellPam.Start();
-    if (aStartCellPam.HasMark())
-    {
-        rLastPaM.SetMark();
-        *rLastPaM.GetMark() = *aEndCellPam.End();
-    }
-    else
-    {
-        rLastPaM.DeleteMark();
-    }
-
+    assert(aEndCellPam.End()->nContent.GetIndex() == aEndCellPam.End()->nNode.GetNode().GetTxtNode()->Len());
     SwNodeRange aCellRange(aStartCellPam.Start()->nNode,
             aEndCellPam.End()->nNode);
     rRowNodes.push_back(aCellRange); // note: invalidates pLastCell!
@@ -2249,7 +2235,6 @@ throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
     std::unique_ptr < SwPaM > pFirstPaM;
     std::vector< std::vector<SwNodeRange> > aTableNodes;
     bool bExcept = false;
-    SwPaM aLastPaM(m_pImpl->m_pDoc->GetNodes());
     for (sal_Int32 nRow = 0; !bExcept && (nRow < rTableRanges.getLength());
             ++nRow)
     {
@@ -2265,7 +2250,7 @@ throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
                     ? ((nRow == 0) ? nullptr : &*aTableNodes.rbegin()->rbegin())
                     : &*aRowNodes.rbegin());
             m_pImpl->ConvertCell((nCell == 0) && (nRow == 0), pRow[nCell],
-                aRowNodes, pFirstPaM, aLastPaM, pLastCell, bExcept);
+                aRowNodes, pFirstPaM, pLastCell, bExcept);
         }
         aTableNodes.push_back(aRowNodes);
     }
commit e4d4ee607efc8ec0e2284f661fd32f0e2ad99e76
Author: Michael Stahl <mstahl at redhat.com>
Date:   Mon May 11 23:47:54 2015 +0200

    sw: fix assert on loading fdo48559-1.rtf
    
    SwXText::convertToTable() is called with 8 cursors that all point to the
    same empty paragraph; that causes the paragraph to be split but the
    SwNodeIndex always point to the 2nd node after the split, so they all
    end up pointing to the last node.  So adjust the last cell's SwNodeIndex
    after split.
    
    Change-Id: I0fdcb19baf2fae840177fd621666c10f4f6f2a62

diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx
index d21a6f2..6f124fa 100644
--- a/sw/source/core/unocore/unotext.cxx
+++ b/sw/source/core/unocore/unotext.cxx
@@ -115,6 +115,7 @@ public:
             ::std::vector<SwNodeRange> & rRowNodes,
             ::std::unique_ptr< SwPaM > & rpFirstPaM,
             SwPaM & rLastPaM,
+            SwNodeRange *const pLastCell,
             bool & rbExcept);
 
 };
@@ -1821,6 +1822,7 @@ void SwXText::Impl::ConvertCell(
     ::std::vector<SwNodeRange> & rRowNodes,
     ::std::unique_ptr< SwPaM > & rpFirstPaM,
     SwPaM & rLastPaM,
+    SwNodeRange *const pLastCell,
     bool & rbExcept)
 {
     if (rCell.getLength() != 2)
@@ -1929,7 +1931,23 @@ void SwXText::Impl::ConvertCell(
             }
             else
             {
+                // note: this may modify rLastPaM too!
                 m_pDoc->getIDocumentContentOperations().SplitNode(*aStartCellPam.Start(), false);
+                sal_uLong const nNewIndex(aStartCellPam.Start()->nNode.GetIndex());
+                if (nNewIndex != nStartCellNodeIndex)
+                {
+                    // aStartCellPam now points to the 2nd node
+                    // the last cell may *also* point to 2nd node now - fix it!
+                    assert(nNewIndex == nStartCellNodeIndex + 1);
+                    if (pLastCell->aEnd.GetIndex() == nNewIndex)
+                    {
+                        --pLastCell->aEnd;
+                        if (pLastCell->aStart.GetIndex() == nNewIndex)
+                        {
+                            --pLastCell->aStart;
+                        }
+                    }
+                }
             }
         }
         else if (nStartCellNodeIndex == (nLastNodeEndIndex + 1))
@@ -1974,7 +1992,7 @@ void SwXText::Impl::ConvertCell(
 
     SwNodeRange aCellRange(aStartCellPam.Start()->nNode,
             aEndCellPam.End()->nNode);
-    rRowNodes.push_back(aCellRange);
+    rRowNodes.push_back(aCellRange); // note: invalidates pLastCell!
     if (bFirstCell)
     {
         rpFirstPaM.reset(new SwPaM(*aStartCellPam.Start()));
@@ -2242,8 +2260,12 @@ throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
 
         for (sal_Int32 nCell = 0; nCell < nCells; ++nCell)
         {
+            SwNodeRange *const pLastCell(
+                (nCell == 0)
+                    ? ((nRow == 0) ? nullptr : &*aTableNodes.rbegin()->rbegin())
+                    : &*aRowNodes.rbegin());
             m_pImpl->ConvertCell((nCell == 0) && (nRow == 0), pRow[nCell],
-                aRowNodes, pFirstPaM, aLastPaM, bExcept);
+                aRowNodes, pFirstPaM, aLastPaM, pLastCell, bExcept);
         }
         aTableNodes.push_back(aRowNodes);
     }


More information about the Libreoffice-commits mailing list