From 1785ede12bbe20bd38e4f869171c19fdb13f6e5d Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Sat, 22 Feb 2025 18:45:41 +0300 Subject: [PATCH] Fix bug #70837 Fix issue with undone of changes when turning off and on accept changes in the live viewer --- common/CollaborativeEditingBase.js | 45 ++++++++++++++++++++++++++---- word/api.js | 6 ++-- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/common/CollaborativeEditingBase.js b/common/CollaborativeEditingBase.js index b62767a135..bbfcb8fbab 100644 --- a/common/CollaborativeEditingBase.js +++ b/common/CollaborativeEditingBase.js @@ -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() { diff --git a/word/api.js b/word/api.js index 72e0999c56..d7f0a0f026 100644 --- a/word/api.js +++ b/word/api.js @@ -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) {