From 982fb392da3cb478f87203e5e614cffd5ae3a853 Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Thu, 21 Nov 2024 01:12:08 +0300 Subject: [PATCH] [de] Improve check for deleted permission range marks --- common/CollaborativeEditingBase.js | 4 +++ word/Editor/Document.js | 35 +++++++++++++++++-- word/Editor/Paragraph.js | 8 ++--- word/Editor/ParagraphContentBase.js | 3 ++ word/Editor/Serialize2.js | 27 ++++++++++---- .../annotations/annotation-mark-base.js | 2 +- .../Editor/annotations/perm-ranges-manager.js | 8 +++++ 7 files changed, 74 insertions(+), 13 deletions(-) diff --git a/common/CollaborativeEditingBase.js b/common/CollaborativeEditingBase.js index 4a52e88877..6370957ddf 100644 --- a/common/CollaborativeEditingBase.js +++ b/common/CollaborativeEditingBase.js @@ -963,6 +963,10 @@ CCollaborativeEditingBase.prototype.Add_DocumentPosition = function(DocumentPos){ this.m_aDocumentPositions.Add_DocumentPosition(DocumentPos); }; + CCollaborativeEditingBase.prototype.Remove_DocumentPosition = function(docPos) + { + this.m_aDocumentPositions.Remove_DocumentPosition(docPos); + }; CCollaborativeEditingBase.prototype.Add_ForeignCursor = function(UserId, DocumentPos, UserShortId){ this.m_aForeignCursorsPos.Remove_DocumentPosition(this.m_aCursorsToUpdate[UserId]); this.m_aForeignCursors[UserId] = DocumentPos; diff --git a/word/Editor/Document.js b/word/Editor/Document.js index 6bb2d61d50..350c1e17d9 100644 --- a/word/Editor/Document.js +++ b/word/Editor/Document.js @@ -3252,9 +3252,40 @@ CDocument.prototype.private_FinalizeDeletingAnnotationsMarks = function() { let info = permMarks[rangeId]; if (info.start && info.end) + { + this.CollaborativeEditing.Remove_DocumentPosition(info.start.docPos); + this.CollaborativeEditing.Remove_DocumentPosition(info.end.docPos); + this.PermRangesManager.checkRange(rangeId); continue; + } + + let docPos = info.start ? info.start.docPos : info.end.docPos; + let mark = info.start ? info.start.mark : info.end.mark; + + let actualMark = info.start ? this.PermRangesManager.getStartMark(rangeId) : this.PermRangesManager.getEndMark(rangeId); + if ((actualMark && actualMark !== mark) || mark.isUseInDocument()) + { + this.CollaborativeEditing.Remove_DocumentPosition(docPos); + this.PermRangesManager.checkRange(rangeId); + continue; + } + this.CollaborativeEditing.Update_DocumentPosition(docPos); + let lastClass = docPos[docPos.length - 1].Class; + + if (lastClass instanceof AscWord.Paragraph || lastClass instanceof AscWord.ParagraphContentWithParagraphLikeContent) + { + let newPosition = Math.min(lastClass.GetElementsCount(), Math.max(docPos[docPos.length - 1].Position, 0)); + lastClass.AddToContent(newPosition, mark); + } + else + { + // TODO: Сделать ветку, если последний элемент Document/DocumentContent + // Ничего не делаем, отрезок должен удалиться на PermRangesManager.checkRange + } + this.CollaborativeEditing.Remove_DocumentPosition(docPos); + this.PermRangesManager.checkRange(rangeId); } this.LoadDocumentState(docState); @@ -25822,11 +25853,11 @@ CDocument.prototype.OnDeleteAnnotationMark = function(mark) if (!this.Action.Additional.DeletedAnnotationMarks) this.Action.Additional.DeletedAnnotationMarks = {perm : {}, comments : {}, bookmarks : {}}; - if (mark.isPerm()) + if (mark.isPermMark()) { let permMarks = this.Action.Additional.DeletedAnnotationMarks.perm; let rangeId = mark.getRangeId(); - if (permMarks[rangeId]) + if (!permMarks[rangeId]) permMarks[rangeId] = {}; let docPos = mark.GetDocumentPositionFromObject(); diff --git a/word/Editor/Paragraph.js b/word/Editor/Paragraph.js index 55e23c8d5e..80d3670a00 100644 --- a/word/Editor/Paragraph.js +++ b/word/Editor/Paragraph.js @@ -13599,15 +13599,15 @@ Paragraph.prototype.Split = function(oNewParagraph, oContentPos, isNoDuplicate) // добавляем в начало нового параграфа. var NewContent = this.Content.slice(nCurPos + 1); - + + this.Internal_Content_Remove2(nCurPos + 1, this.Content.length - nCurPos - 1); + this.CheckParaEnd(); + // Очищаем новый параграф и добавляем в него Right элемент и NewContent oNewParagraph.Internal_Content_Remove2(0, oNewParagraph.Content.length); oNewParagraph.ConcatContent(NewContent); oNewParagraph.Internal_Content_Add(0, NewElement); oNewParagraph.CorrectContent(); - - this.Internal_Content_Remove2(nCurPos + 1, this.Content.length - nCurPos - 1); - this.CheckParaEnd(); } if (false !== localTrack) diff --git a/word/Editor/ParagraphContentBase.js b/word/Editor/ParagraphContentBase.js index f994f5969b..841a3c1ab5 100644 --- a/word/Editor/ParagraphContentBase.js +++ b/word/Editor/ParagraphContentBase.js @@ -4965,3 +4965,6 @@ function private_ParagraphContentChangesCheckLock(lockData) lockData.lock(); } } +//--------------------------------------------------------export---------------------------------------------------- +AscWord.ParagraphContentBase = CParagraphContentBase; +AscWord.ParagraphContentWithParagraphLikeContent = CParagraphContentWithParagraphLikeContent; diff --git a/word/Editor/Serialize2.js b/word/Editor/Serialize2.js index d203e39833..b86a2f5d4c 100644 --- a/word/Editor/Serialize2.js +++ b/word/Editor/Serialize2.js @@ -12908,8 +12908,13 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, curNot res = readMoveRangeStart(length, this.bcr, this.stream, this.oReadResult, null, false); } else if (c_oSerDocTableType.MoveToRangeEnd === type && this.oReadResult.checkReadRevisions()) { res = readMoveRangeEnd(length, this.bcr, this.stream, this.oReadResult, this.oReadResult.lastPar, true); - } else - res = c_oSerConstants.ReadUnknown; + } else if (c_oSerParType.PermStart === type) { + res = this.ReadPermStart(length, null); + } else if (c_oSerParType.PermEnd === type) { + res = this.ReadPermEnd(length, this.oReadResult.lastPar); + } else { + res = c_oSerConstants.ReadUnknown; + } return res; }; this.Read_Row = function(type, length, Row) @@ -12961,8 +12966,13 @@ function Binary_DocumentTableReader(doc, oReadResult, openParams, stream, curNot res = readMoveRangeStart(length, this.bcr, this.stream, this.oReadResult, null, false); } else if (c_oSerDocTableType.MoveToRangeEnd === type && this.oReadResult.checkReadRevisions()) { res = readMoveRangeEnd(length, this.bcr, this.stream, this.oReadResult, this.oReadResult.lastPar, true); - } else - res = c_oSerConstants.ReadUnknown; + } else if (c_oSerParType.PermStart === type) { + res = this.ReadPermStart(length, null); + } else if (c_oSerParType.PermEnd === type) { + res = this.ReadPermEnd(length, this.oReadResult.lastPar); + } else { + res = c_oSerConstants.ReadUnknown; + } return res; }; this.ReadCell = function(type, length, cell) @@ -13895,8 +13905,13 @@ function Binary_oMathReader(stream, oReadResult, curNote, openParams) res = readMoveRangeStart(length, this.bcr, this.stream, this.oReadResult, paragraphContent, false); } else if (c_oSer_OMathContentType.MoveToRangeEnd === type && this.oReadResult.checkReadRevisions()) { res = readMoveRangeEnd(length, this.bcr, this.stream, this.oReadResult, paragraphContent); - } else - res = c_oSerConstants.ReadUnknown; + } else if (c_oSerParType.PermStart === type) { + res = this.ReadPermStart(length, null); + } else if (c_oSerParType.PermEnd === type) { + res = this.ReadPermEnd(length, this.oReadResult.lastPar); + } else { + res = c_oSerConstants.ReadUnknown; + } if (oElem && bLast) oElem.Correct_Content(false); diff --git a/word/Editor/annotations/annotation-mark-base.js b/word/Editor/annotations/annotation-mark-base.js index cc2c0360f8..1ec1e3f6da 100644 --- a/word/Editor/annotations/annotation-mark-base.js +++ b/word/Editor/annotations/annotation-mark-base.js @@ -69,7 +69,7 @@ if (!paragraph) return false; - return paragraph.IsUseInDocument(); + return (paragraph && !!paragraph.Get_PosByElement(this)); }; AnnotationMarkBase.prototype.getParagraph = function() { diff --git a/word/Editor/annotations/perm-ranges-manager.js b/word/Editor/annotations/perm-ranges-manager.js index 99158d4d41..50d740c23c 100644 --- a/word/Editor/annotations/perm-ranges-manager.js +++ b/word/Editor/annotations/perm-ranges-manager.js @@ -89,6 +89,14 @@ marksToCheck.length = 0; }; + /** + * Проверяем заданный отрезок, если он невалидный или пустой, тогда удаляем его из документа + * @param {number} rangeId + */ + PermRangesManager.prototype.checkRange = function(rangeId) + { + // TODO: implement + }; function registerPermRangeMark(mark) {