Commit 3ebed08c authored by Ilya Kirillov's avatar Ilya Kirillov

Fixed bug with incorrect content of paragraph/document after collaboration undo.

parent 2cdd3350
......@@ -734,6 +734,49 @@ CWordCollaborativeEditing.prototype.Undo = function()
this.m_aAllChanges.push(arrReverseChanges[nIndex]);
}
// Может так случиться, что в каких-то классах DocumentContent удалились все элементы, либо
// в классе Paragraph удалился знак конца параграфа. Нам необходимо проверить все классы на корректность, и если
// нужно, добавить дополнительные изменения.
var mapDocumentContents = {};
var mapParagraphs = {};
for (var nIndex = 0, nCount = arrReverseChanges.length; nIndex < nCount; ++nIndex)
{
var oChange = arrReverseChanges[nIndex];
var oClass = oChange.GetClass();
if (oClass instanceof CDocument || oClass instanceof CDocumentContent)
mapDocumentContents[oClass.Get_Id()] = oClass;
else if (oClass instanceof Paragraph)
mapParagraphs[oClass.Get_Id()] = oClass;
else if (oClass instanceof ParaRun && true === oChange.IsContentChange() && oClass.Get_Paragraph())
mapParagraphs[oClass.Get_Paragraph().Get_Id()] = oClass.Get_Paragraph();
}
// Создаем точку в истории. Делаем действия через обычные функции (с отключенным пересчетом), которые пишут в
// историю. Сохраняем список изменений в новой точке, удаляем данную точку.
var oHistory = AscCommon.History;
oHistory.CreateNewPointForCollectChanges();
for (var sId in mapDocumentContents)
{
var oDocumentContent = mapDocumentContents[sId];
if (oDocumentContent.Content.length <= 0)
{
var oNewParagraph = new Paragraph(oLogicDocument.Get_DrawingDocument(), oDocumentContent, 0, 0, 0, 0, 0, false);
oDocumentContent.Add_ToContent(0, oNewParagraph);
}
}
for (var sId in mapParagraphs)
{
var oParagraph = mapParagraphs[sId];
oParagraph.CheckParaEnd();
}
var oHistoryPoint = oHistory.Points[oHistory.Points.length - 1];
for (var nIndex = 0, nCount = oHistoryPoint.Items.length; nIndex < nCount; ++nIndex)
{
arrReverseChanges.push(oHistoryPoint.Items[nIndex].Data);
}
oHistory.Remove_LastPoint();
var oBinaryWriter = AscCommon.History.BinaryWriter;
var aSendingChanges = [];
for (var nIndex = 0, nCount = arrReverseChanges.length; nIndex < nCount; ++nIndex)
......
......@@ -358,6 +358,23 @@ CHistory.prototype =
// Удаляем ненужные точки
this.Points.length = this.Index + 1;
},
/**
* Специальная функция, для создания точки, чтобы отловить все изменения, которые происходят. После использования
* данная точка ДОЛЖНА быть удалена через функцию Remove_LastPoint.
*/
CreateNewPointForCollectChanges : function()
{
this.Points[++this.Index] = {
State : null,
Items : [],
Time : null,
Additional : {},
Description : -1
};
this.Points.length = this.Index + 1;
},
Remove_LastPoint : function()
{
......
......@@ -12193,6 +12193,17 @@ Paragraph.prototype.private_GetFootnoteRefsInLine = function(CurLine)
}
return arrFootnotes;
};
Paragraph.prototype.CheckParaEnd = function()
{
// TODO (ParaEnd): Как избавимся от ParaEnd убрать эту проверку
if (this.Content.length <= 0 || para_Run !== this.Content[this.Content.length - 1].Type || null === this.Content[this.Content.length - 1].GetParaEnd())
{
var oEndRun = new ParaRun(this);
oEndRun.Set_Pr(this.TextPr.Value.Copy());
oEndRun.Add_ToContent(0, new ParaEnd());
this.Add_ToContent(this.Content.length, oEndRun);
}
};
var pararecalc_0_All = 0;
var pararecalc_0_None = 1;
......
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