Commit 0a64def2 authored by Ilya Kirillov's avatar Ilya Kirillov

Fixed bug with creating an reverted changes for adding/removing elements from...

Fixed bug with creating an reverted changes for adding/removing elements from Document/DocumentContent.
parent 8530dcf3
......@@ -73,94 +73,50 @@ AscCommon.extendClass(CChangesDocumentAddItem, AscDFH.CChangesBaseContentChange)
CChangesDocumentAddItem.prototype.Type = AscDFH.historyitem_Document_AddItem;
CChangesDocumentAddItem.prototype.Undo = function()
{
var Pos = this.Pos;
var oDocument = this.Class;
var Elements = oDocument.Content.splice(Pos, 1);
oDocument.private_RecalculateNumbering(Elements);
if(oDocument.SectionsInfo)
for (var nIndex = 0, nCount = this.Items.length; nIndex < nCount; ++nIndex)
{
oDocument.SectionsInfo.Update_OnRemove(Pos, 1);
}
var Pos = true !== this.UseArray ? this.Pos : this.PosArray[nIndex];
var Elements = oDocument.Content.splice(Pos, 1);
oDocument.private_RecalculateNumbering(Elements);
if (oDocument.SectionsInfo)
{
oDocument.SectionsInfo.Update_OnRemove(Pos, 1);
}
if (Pos > 0)
{
if (Pos <= oDocument.Content.length - 1)
if (Pos > 0)
{
oDocument.Content[Pos - 1].Next = oDocument.Content[Pos];
oDocument.Content[Pos].Prev = oDocument.Content[Pos - 1];
if (Pos <= oDocument.Content.length - 1)
{
oDocument.Content[Pos - 1].Next = oDocument.Content[Pos];
oDocument.Content[Pos].Prev = oDocument.Content[Pos - 1];
}
else
{
oDocument.Content[Pos - 1].Next = null;
}
}
else
else if (Pos <= oDocument.Content.length - 1)
{
oDocument.Content[Pos - 1].Next = null;
oDocument.Content[Pos].Prev = null;
}
}
else if (Pos <= oDocument.Content.length - 1)
{
oDocument.Content[Pos].Prev = null;
}
};
CChangesDocumentAddItem.prototype.Redo = function()
{
if (this.Items.length <= 0)
return;
var Element = this.Items[0];
var Pos = this.Pos;
var oDocument = this.Class;
oDocument.Content.splice(Pos, 0, Element);
oDocument.private_RecalculateNumbering([Element]);
if(oDocument.SectionsInfo)
{
oDocument.SectionsInfo.Update_OnAdd(Pos, [Element]);
}
if (Pos > 0)
{
oDocument.Content[Pos - 1].Next = Element;
Element.Prev = oDocument.Content[Pos - 1];
}
else
for (var nIndex = 0, nCount = this.Items.length; nIndex < nCount; ++nIndex)
{
Element.Prev = null;
}
var Element = this.Items[nIndex];
var Pos = true !== this.UseArray ? this.Pos + nIndex : this.PosArray[nIndex];
if (Pos < oDocument.Content.length - 1)
{
oDocument.Content[Pos + 1].Prev = Element;
Element.Next = oDocument.Content[Pos + 1];
}
else
{
Element.Next = null;
}
Element.Parent = oDocument;
};
CChangesDocumentAddItem.prototype.private_WriteItem = function(Writer, Item)
{
Writer.WriteString2(Item.Get_Id());
};
CChangesDocumentAddItem.prototype.private_ReadItem = function(Reader)
{
return AscCommon.g_oTableId.Get_ById(Reader.GetString2());
};
CChangesDocumentAddItem.prototype.Load = function(Color)
{
if (this.Items.length <= 0 || this.PosArray.length <= 0)
return;
var oDocument = this.Class;
var Pos = oDocument.m_oContentChanges.Check(AscCommon.contentchanges_Add, this.PosArray[0]);
var Element = this.Items[0];
Pos = Math.min(Pos, oDocument.Content.length);
oDocument.Content.splice(Pos, 0, Element);
oDocument.private_RecalculateNumbering([Element]);
if (oDocument.SectionsInfo)
{
oDocument.SectionsInfo.Update_OnAdd(Pos, [Element]);
}
if (null != Element)
{
if (Pos > 0)
{
oDocument.Content[Pos - 1].Next = Element;
......@@ -171,10 +127,10 @@ CChangesDocumentAddItem.prototype.Load = function(Color)
Element.Prev = null;
}
if (Pos <= oDocument.Content.length - 1)
if (Pos < oDocument.Content.length - 1)
{
oDocument.Content[Pos].Prev = Element;
Element.Next = oDocument.Content[Pos];
oDocument.Content[Pos + 1].Prev = Element;
Element.Next = oDocument.Content[Pos + 1];
}
else
{
......@@ -182,16 +138,60 @@ CChangesDocumentAddItem.prototype.Load = function(Color)
}
Element.Parent = oDocument;
}
};
CChangesDocumentAddItem.prototype.private_WriteItem = function(Writer, Item)
{
Writer.WriteString2(Item.Get_Id());
};
CChangesDocumentAddItem.prototype.private_ReadItem = function(Reader)
{
return AscCommon.g_oTableId.Get_ById(Reader.GetString2());
};
CChangesDocumentAddItem.prototype.Load = function(Color)
{
var oDocument = this.Class;
for (var nIndex = 0, nCount = this.Items.length; nIndex < nCount; ++nIndex)
{
var Pos = oDocument.m_oContentChanges.Check(AscCommon.contentchanges_Add, true !== this.UseArray ? this.Pos + nIndex : this.PosArray[nIndex]);
var Element = this.Items[nIndex];
oDocument.Content.splice(Pos, 0, Element);
oDocument.private_RecalculateNumbering([Element]);
if(oDocument.SectionsInfo)
Pos = Math.min(Pos, oDocument.Content.length);
if (null != Element)
{
oDocument.SectionsInfo.Update_OnAdd(Pos, [Element]);
}
oDocument.private_ReindexContent(Pos);
if (Pos > 0)
{
oDocument.Content[Pos - 1].Next = Element;
Element.Prev = oDocument.Content[Pos - 1];
}
else
{
Element.Prev = null;
}
AscCommon.CollaborativeEditing.Update_DocumentPositionsOnAdd(oDocument, Pos);
if (Pos <= oDocument.Content.length - 1)
{
oDocument.Content[Pos].Prev = Element;
Element.Next = oDocument.Content[Pos];
}
else
{
Element.Next = null;
}
Element.Parent = oDocument;
oDocument.Content.splice(Pos, 0, Element);
oDocument.private_RecalculateNumbering([Element]);
if (oDocument.SectionsInfo)
{
oDocument.SectionsInfo.Update_OnAdd(Pos, [Element]);
}
oDocument.private_ReindexContent(Pos);
AscCommon.CollaborativeEditing.Update_DocumentPositionsOnAdd(oDocument, Pos);
}
}
};
CChangesDocumentAddItem.prototype.IsRelated = function(oChanges)
......@@ -291,7 +291,7 @@ CChangesDocumentRemoveItem.prototype.Load = function(Color)
var oDocument = this.Class;
for (var nIndex = 0, nCount = this.Items.length; nIndex < nCount; ++nIndex)
{
var Pos = oDocument.m_oContentChanges.Check(AscCommon.contentchanges_Remove, this.PosArray[nIndex]);
var Pos = oDocument.m_oContentChanges.Check(AscCommon.contentchanges_Remove, true !== this.UseArray ? this.Pos : this.PosArray[nIndex]);
// действие совпало, не делаем его
if (false === Pos)
......
......@@ -65,62 +65,64 @@ AscCommon.extendClass(CChangesDocumentContentAddItem, AscDFH.CChangesBaseContent
CChangesDocumentContentAddItem.prototype.Type = AscDFH.historyitem_DocumentContent_AddItem;
CChangesDocumentContentAddItem.prototype.Undo = function()
{
var Pos = this.Pos;
var oDocument = this.Class;
var Elements = oDocument.Content.splice(Pos, 1);
oDocument.private_RecalculateNumbering(Elements);
if (Pos > 0)
for (var nIndex = 0, nCount = this.Items.length; nIndex < nCount; ++nIndex)
{
if (Pos <= oDocument.Content.length - 1)
var Pos = true !== this.UseArray ? this.Pos : this.PosArray[nIndex];
var Elements = oDocument.Content.splice(Pos, 1);
oDocument.private_RecalculateNumbering(Elements);
if (Pos > 0)
{
oDocument.Content[Pos - 1].Next = oDocument.Content[Pos];
oDocument.Content[Pos].Prev = oDocument.Content[Pos - 1];
if (Pos <= oDocument.Content.length - 1)
{
oDocument.Content[Pos - 1].Next = oDocument.Content[Pos];
oDocument.Content[Pos].Prev = oDocument.Content[Pos - 1];
}
else
{
oDocument.Content[Pos - 1].Next = null;
}
}
else
else if (Pos <= oDocument.Content.length - 1)
{
oDocument.Content[Pos - 1].Next = null;
oDocument.Content[Pos].Prev = null;
}
}
else if (Pos <= oDocument.Content.length - 1)
{
oDocument.Content[Pos].Prev = null;
}
};
CChangesDocumentContentAddItem.prototype.Redo = function()
{
if (this.Items.length <= 0)
return;
var oDocument = this.Class;
for (var nIndex = 0, nCount = this.Items.length; nIndex < nCount; ++nIndex)
{
var Element = this.Items[nIndex];
var Pos = true !== this.UseArray ? this.Pos + nIndex : this.PosArray[nIndex];
var Element = this.Items[0];
var Pos = this.Pos;
oDocument.Content.splice(Pos, 0, Element);
oDocument.private_RecalculateNumbering([Element]);
var oDocument = this.Class;
oDocument.Content.splice(Pos, 0, Element);
oDocument.private_RecalculateNumbering([Element]);
if (Pos > 0)
{
oDocument.Content[Pos - 1].Next = Element;
Element.Prev = oDocument.Content[Pos - 1];
}
else
{
Element.Prev = null;
}
if (Pos > 0)
{
oDocument.Content[Pos - 1].Next = Element;
Element.Prev = oDocument.Content[Pos - 1];
}
else
{
Element.Prev = null;
}
if (Pos < oDocument.Content.length - 1)
{
oDocument.Content[Pos + 1].Prev = Element;
Element.Next = oDocument.Content[Pos + 1];
}
else
{
Element.Next = null;
}
if (Pos < oDocument.Content.length - 1)
{
oDocument.Content[Pos + 1].Prev = Element;
Element.Next = oDocument.Content[Pos + 1];
}
else
{
Element.Next = null;
Element.Parent = oDocument;
}
Element.Parent = oDocument;
};
CChangesDocumentContentAddItem.prototype.private_WriteItem = function(Writer, Item)
{
......@@ -136,41 +138,43 @@ CChangesDocumentContentAddItem.prototype.Load = function(Color)
return;
var oDocument = this.Class;
for (var nIndex = 0, nCount = this.Items.length; nIndex < nCount; ++nIndex)
{
var Pos = oDocument.m_oContentChanges.Check(AscCommon.contentchanges_Add, true !== this.UseArray ? this.Pos + nIndex : this.PosArray[nIndex]);
var Element = this.Items[nIndex];
var Pos = oDocument.m_oContentChanges.Check(AscCommon.contentchanges_Add, this.PosArray[0]);
var Element = this.Items[0];
Pos = Math.min(Pos, oDocument.Content.length);
Pos = Math.min(Pos, oDocument.Content.length);
if (null != Element)
{
if (Pos > 0)
if (null != Element)
{
oDocument.Content[Pos - 1].Next = Element;
Element.Prev = oDocument.Content[Pos - 1];
}
else
{
Element.Prev = null;
}
if (Pos > 0)
{
oDocument.Content[Pos - 1].Next = Element;
Element.Prev = oDocument.Content[Pos - 1];
}
else
{
Element.Prev = null;
}
if (Pos <= oDocument.Content.length - 1)
{
oDocument.Content[Pos].Prev = Element;
Element.Next = oDocument.Content[Pos];
}
else
{
Element.Next = null;
}
if (Pos <= oDocument.Content.length - 1)
{
oDocument.Content[Pos].Prev = Element;
Element.Next = oDocument.Content[Pos];
}
else
{
Element.Next = null;
}
Element.Parent = oDocument;
Element.Parent = oDocument;
oDocument.Content.splice(Pos, 0, Element);
oDocument.private_RecalculateNumbering([Element]);
oDocument.private_ReindexContent(Pos);
oDocument.Content.splice(Pos, 0, Element);
oDocument.private_RecalculateNumbering([Element]);
oDocument.private_ReindexContent(Pos);
AscCommon.CollaborativeEditing.Update_DocumentPositionsOnAdd(oDocument, Pos);
AscCommon.CollaborativeEditing.Update_DocumentPositionsOnAdd(oDocument, Pos);
}
}
};
CChangesDocumentContentAddItem.prototype.IsRelated = function(oChanges)
......@@ -265,7 +269,7 @@ CChangesDocumentContentRemoveItem.prototype.Load = function(Color)
var oDocument = this.Class;
for (var nIndex = 0, nCount = this.Items.length; nIndex < nCount; ++nIndex)
{
var Pos = oDocument.m_oContentChanges.Check(AscCommon.contentchanges_Remove, this.PosArray[nIndex]);
var Pos = oDocument.m_oContentChanges.Check(AscCommon.contentchanges_Remove, true !== this.UseArray ? this.Pos : this.PosArray[nIndex]);
// действие совпало, не делаем его
if (false === Pos)
......
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