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