sw/source/core/fields/reffld.cxx |   18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

New commits:
commit 718524619bf8cc96325aed87b72735741fe93912
Author: Michael Stahl <mst...@redhat.com>
Date:   Wed Jan 29 22:38:21 2014 +0100

    fdo#63553: sw: fix copy/paste of cross references
    
    If one of aIds or aDestIds contains nSeqNo then adding an identity
    mapping for it will actually re-define a previous mapping.  Likely this
    can only happen when clipboard document is the source.
    
    (regression from 44f971506c0ed37928c48e55d8007f24b0c43a5f)
    
    (also it looks like 4b0b0a5b3045902d9a6b95510ec30a3027181e29 has subtly
     changed what the "else" branch does when it is erroneously taken -
     results are differently wrong)
    
    Change-Id: I34e2979e45cffeb62ebf3d7b3e5ac6d2afff0c2b
    (cherry picked from commit bb665affbd8870652ade3951d626d76e99143f67)
    Reviewed-on: https://gerrit.libreoffice.org/7730
    Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk>
    Tested-by: Miklos Vajna <vmik...@collabora.co.uk>
    (cherry picked from commit 139342a9ad5995058081a47a24818b14581735a5)
    Reviewed-on: https://gerrit.libreoffice.org/7740
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    Tested-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sw/source/core/fields/reffld.cxx b/sw/source/core/fields/reffld.cxx
index 4c668b0..ba0e4bb 100644
--- a/sw/source/core/fields/reffld.cxx
+++ b/sw/source/core/fields/reffld.cxx
@@ -997,7 +997,7 @@ void _RefIdsMap::Init( SwDoc& rDoc, SwDoc& rDestDoc, bool 
bField )
         for ( std::set<sal_uInt16>::iterator pIt = aDstIds.begin(); pIt != 
aDstIds.end(); ++pIt )
             AddId( GetFirstUnusedId(aIds), *pIt );
 
-        // Change the Sequence number of all the SetExp fields in the 
destination document
+        // Change the Sequence number of all SetExp fields in the source 
document
         SwFieldType* pType = rDoc.GetFldType( RES_SETEXPFLD, aName, false );
         if( pType )
         {
@@ -1051,16 +1051,24 @@ void _RefIdsMap::Check( SwDoc& rDoc, SwDoc& rDestDoc, 
SwGetRefField& rFld,
 {
     Init( rDoc, rDestDoc, bField);
 
-    // dann teste mal, ob die Nummer schon vergeben ist
-    // oder ob eine neue bestimmt werden muss.
     sal_uInt16 nSeqNo = rFld.GetSeqNo();
-    if( aIds.count( nSeqNo ) && aDstIds.count( nSeqNo ))
+
+    // Check if the number is used in both documents
+    // Note: For fields, aIds contains both the ids of SetExp from rDestDoc
+    // and the targets of the already remapped ones from rDoc.
+    // It is possible that aDstIds contains numbers that aIds does not contain!
+    // For example, copying a selection to clipboard that does not contain
+    // the first SwSetExpField will result in id 0 missing, then pasting that
+    // into empty document gives a mapping 1->0 ... N->N-1 (fdo#63553).
+    if (aIds.count(nSeqNo) || aDstIds.count(nSeqNo))
     {
         // Number already taken, so need a new one.
         if( sequencedIds.count(nSeqNo) )
             rFld.SetSeqNo( sequencedIds[nSeqNo] );
         else
         {
+            assert(!bField || !aDstIds.count(nSeqNo)); // postcond of Init
+
             sal_uInt16 n = GetFirstUnusedId( aIds );
 
             // die neue SeqNo eintragen, damit die "belegt" ist
@@ -1082,7 +1090,7 @@ void _RefIdsMap::Check( SwDoc& rDoc, SwDoc& rDestDoc, 
SwGetRefField& rFld,
     }
     else
     {
-        AddId( nSeqNo, nSeqNo );
+        AddId( nSeqNo, nSeqNo ); // this requires that nSeqNo is unused in 
both!
     }
 }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to