Fix issue with undone of changes when turning off and on accept changes in the live viewer
This commit is contained in:
Ilya Kirillov
2025-02-22 18:45:41 +03:00
parent 888a9e9696
commit 1785ede12b
2 changed files with 41 additions and 10 deletions

View File

@ -177,6 +177,7 @@
this.m_aUsers = []; // Список текущих пользователей, редактирующих данный документ
this.m_aChanges = []; // Массив с изменениями других пользователей
this.m_nUndoBeforeApply = 0; // The number of changes we need to undo before the other changes can be accepted
this.m_aNeedUnlock = []; // Массив со списком залоченных объектов(которые были залочены другими пользователями)
this.m_aNeedUnlock2 = []; // Массив со списком залоченных объектов(которые были залочены на данном клиенте)
@ -348,10 +349,18 @@
};
CCollaborativeEditingBase.prototype.Have_OtherChanges = function()
{
return (0 < this.m_aChanges.length);
return (0 < this.m_aChanges.length || this.m_nUndoBeforeApply > 0);
};
CCollaborativeEditingBase.prototype.Apply_Changes = function(fEndCallBack)
{
if (this.m_nUndoBeforeApply)
{
let state = this._PreUndo();
let changes = this.CoHistory.UndoGlobalChanges(this.m_nUndoBeforeApply);
this._PostUndo(state, changes);
this.m_nUndoBeforeApply = 0;
}
if (this.m_aChanges.length > 0)
{
this.GetEditorApi().sendEvent("asc_onBeforeApplyChanges");
@ -1239,15 +1248,37 @@
};
CCollaborativeEditingBase.prototype.UndoGlobal = function(count)
{
// If we have unaccepted changes then we first remove from them
if (this.m_aChanges.length >= count)
{
this.m_aChanges.length -= count;
count = 0;
}
else
{
count -= this.m_aChanges.length;
this.m_aChanges.length = 0;
}
if (!count)
return;
let state = this.PreUndo();
let changes = this.CoHistory.UndoGlobalChanges(count);
this.PostUndo(state, changes);
let editor = this.GetEditorApi();
if (editor.getViewMode() && !editor.isLiveViewer())
{
this.m_nUndoBeforeApply += count;
}
else
{
let state = this.PreUndo();
let changes = this.CoHistory.UndoGlobalChanges(count);
this.PostUndo(state, changes);
}
};
CCollaborativeEditingBase.prototype.UndoGlobalPoint = function()
{
// TODO: Handle unaccepted changes from this.m_aChanges
let state = this.PreUndo();
let changes = this.CoHistory.UndoGlobalPoint();
this.PostUndo(state, changes);
@ -1256,6 +1287,8 @@
{
if (true === this.Get_GlobalLock())
return;
// TODO: Handle unaccepted changes from this.m_aChanges
let state = this.PreUndo();
let changes = this.CoHistory.UndoOwnPoint();
@ -1267,7 +1300,7 @@
};
CCollaborativeEditingBase.prototype.GetAllChangesCount = function()
{
return this.CoHistory.GetChangeCount();
return this.CoHistory.GetChangeCount() - this.m_nUndoBeforeApply + this.m_aChanges.length;
};
CCollaborativeEditingBase.prototype.CanUndo = function()
{

View File

@ -1897,10 +1897,8 @@ background-repeat: no-repeat;\
};
this.CoAuthoringApi.onChangesIndex = function(changesIndex)
{
if (t.isLiveViewer() && changesIndex >= 0 && changesIndex < AscCommon.CollaborativeEditing.GetAllChangesCount()) {
let count = AscCommon.CollaborativeEditing.GetAllChangesCount() - changesIndex;
AscCommon.CollaborativeEditing.UndoGlobal(count);
}
let count = AscCommon.CollaborativeEditing.GetAllChangesCount() - changesIndex;
AscCommon.CollaborativeEditing.UndoGlobal(count);
};
this.CoAuthoringApi.onRecalcLocks = function(e)
{