Commit 5f3b1e41 authored by Ilya Kirillov's avatar Ilya Kirillov

Reworked algorithm of Undo in fast collaboration mode. Fixed bug #33883. Fixed bug #33884.

parent 3a65ee43
......@@ -884,11 +884,6 @@ CCollaborativeEditingBase.prototype.private_RestoreDocumentState = function(DocS
var oIndexes = this.m_aOwnChangesIndexes[this.m_aOwnChangesIndexes.length - 1];
var nPosition = oIndexes.Position;
var nCount = oIndexes.Count;
var nOverallCount = this.m_aAllChanges.length;
var oContentChangesMap = {
};
for (var nIndex = nCount - 1; nIndex >= 0; --nIndex)
{
......@@ -901,8 +896,10 @@ CCollaborativeEditingBase.prototype.private_RestoreDocumentState = function(DocS
{
var _oChange = oChange.Copy();
if (this.private_CommutateContentChanges(oContentChangesMap, oClass, _oChange, nPosition + nCount))
if (this.private_CommutateContentChanges(_oChange, nPosition + nCount))
arrChanges.push(_oChange);
oChange.SetReverted(true);
}
else
{
......@@ -921,7 +918,10 @@ CCollaborativeEditingBase.prototype.private_RestoreDocumentState = function(DocS
{
var oReverseChange = arrChanges[nIndex].CreateReverseChange();
if (oReverseChange)
{
arrReverseChanges.push(oReverseChange);
oReverseChange.SetReverted(true);
}
}
// Накатываем изменения в данном клиенте
......@@ -1096,56 +1096,43 @@ CCollaborativeEditingBase.prototype.private_RestoreDocumentState = function(DocS
{
return this.m_aOwnChangesIndexes.length <= 0 ? false : true;
};
CCollaborativeEditingBase.prototype.private_CommutateContentChanges = function(oMap, oClass, oChange, nStartPosition)
CCollaborativeEditingBase.prototype.private_CommutateContentChanges = function(oChange, nStartPosition)
{
var arrOtherActions = [];
var arrActions = oChange.ConvertToSimpleActions();
var arrCommutateActions = [];
if (oMap[oClass.Get_Id()])
{
arrOtherActions = oMap[oClass.Get_Id()];
}
else
for (var nActionIndex = arrActions.length - 1; nActionIndex >= 0; --nActionIndex)
{
var oAction = arrActions[nActionIndex];
var oResult = oAction;
for (var nIndex = nStartPosition, nOverallCount = this.m_aAllChanges.length; nIndex < nOverallCount; ++nIndex)
{
var oTempChange = this.m_aAllChanges[nIndex];
if (!oTempChange)
continue;
if (oChange.IsRelated(oTempChange))
{
arrOtherActions.push(oTempChange.ConvertToSimpleActions());
}
}
oMap[oClass.Get_Id()] = arrOtherActions;
}
var arrActions = oChange.ConvertToSimpleActions();
var arrCommutateActions = [];
for (var nActionIndex = arrActions.length - 1; nActionIndex >= 0; --nActionIndex)
{
var oAction = arrActions[nActionIndex];
var oResult = oAction;
for (var nIndex = 0, nOtherActionsCount = arrOtherActions.length; nIndex < nOtherActionsCount; ++nIndex)
if (oChange.IsRelated(oTempChange) && true !== oTempChange.IsReverted())
{
var arrOActions = arrOtherActions[nIndex];
for (var nIndex2 = 0, nOtherActionsCount2 = arrOActions.length; nIndex2 < nOtherActionsCount2; ++nIndex2)
var arrOtherActions = oTempChange.ConvertToSimpleActions();
for (var nIndex2 = 0, nOtherActionsCount2 = arrOtherActions.length; nIndex2 < nOtherActionsCount2; ++nIndex2)
{
var oOtherAction = arrOActions[nIndex2];
var oOtherAction = arrOtherActions[nIndex2];
if (false === this.private_Commutate(oAction, oOtherAction))
{
arrOActions.splice(nIndex2, 1);
arrOtherActions.splice(nIndex2, 1);
oResult = null;
break;
}
}
if (null === oResult)
oTempChange.ConvertFromSimpleActions(arrOtherActions);
}
if (!oResult)
break;
}
if (null !== oResult)
......
......@@ -2898,6 +2898,8 @@
function CChangesBase(Class)
{
this.Class = Class;
this.Reverted = false;
}
CChangesBase.prototype.Type = window['AscDFH'].historyitem_Unknown_Unknown;
CChangesBase.prototype.Undo = function()
......@@ -2949,6 +2951,14 @@
{
return false;
};
CChangesBase.prototype.IsReverted = function()
{
return this.Reverted;
};
CChangesBase.prototype.SetReverted = function(isReverted)
{
this.Reverted = isReverted;
};
window['AscDFH'].CChangesBase = CChangesBase;
/**
* Базовый класс для изменений, которые меняют содержимое родительского класса.*
......@@ -2964,6 +2974,8 @@
this.UseArray = false;
this.PosArray = [];
this.Add = isAdd;
this.Reverted = false;
}
AscCommon.extendClass(CChangesBaseContentChange, CChangesBase);
CChangesBaseContentChange.prototype.IsContentChange = function()
......
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