From bd66a7f566d55717c33c9ef69ebd7ea6f66a827d Mon Sep 17 00:00:00 2001 From: Vladimir Privezenov Date: Fri, 17 Jan 2025 19:46:33 +0300 Subject: [PATCH] Fix comparing two words with equal end or start --- vendor/delta.js | 1 + word/Editor/Comparison.js | 121 +++++++++++----------- word/Editor/Merge.js | 205 ++++++++------------------------------ 3 files changed, 102 insertions(+), 225 deletions(-) diff --git a/vendor/delta.js b/vendor/delta.js index 3f74f13659..fcd81f89b6 100644 --- a/vendor/delta.js +++ b/vendor/delta.js @@ -1132,4 +1132,5 @@ window["AscCommon"].ParameterBuffer = ParameterBuffer; window["AscCommon"].DeltaCollector = DeltaCollector; window["AscCommon"].AttachedOperation = AttachedOperation; + window["AscCommon"].UPDATE_FOREST_TYPE = UPDATE_FOREST_TYPE; })(window); diff --git a/word/Editor/Comparison.js b/word/Editor/Comparison.js index 18fc84c007..fe3b43c698 100644 --- a/word/Editor/Comparison.js +++ b/word/Editor/Comparison.js @@ -885,8 +885,7 @@ } return element; }; - CNode.prototype.cleanEndOfInsert = function (aContentToInsert, idxOfChange, comparison) { - const oChange = this.changes[idxOfChange]; + CNode.prototype.cleanEndOfInsert = function (aContentToInsert, oChange, comparison) { const oNode = oChange.insert[oChange.insert.length - 1]; const oLastText = oNode.element; const oEndOfInsertRun = oNode.getContentElement(); @@ -969,8 +968,7 @@ } }; - CNode.prototype.cleanStartOfInsertSameRun = function (oNewRun, idxOfChange) { - const oChange = this.changes[idxOfChange]; + CNode.prototype.cleanStartOfInsertSameRun = function (oNewRun, oChange) { const oNode = oChange.insert[0]; const oFirstText = oNode.element; if(oNewRun) @@ -999,8 +997,7 @@ return oNewRun; }; - CNode.prototype.cleanStartOfInsertDifferentRun = function (aContentToInsert, posOfLastInsertRun, idxOfChange, comparison) { - const oChange = this.changes[idxOfChange]; + CNode.prototype.cleanStartOfInsertDifferentRun = function (aContentToInsert, posOfLastInsertRun, oChange, comparison) { const oFirstNode = oChange.insert[0]; const oLastNode = oChange.insert[oChange.insert.length - 1]; const oFirstText = oFirstNode.element; @@ -1055,10 +1052,9 @@ } } }; - CNode.prototype.checkCommentsFromInsert = function (idxOfChange, comparison) + CNode.prototype.checkCommentsFromInsert = function (oChange, comparison) { const mapRevisedComments = {}; - const oChange = this.changes[idxOfChange]; const arrRevisedComments = []; for (let i = 0; i < oChange.insert.length; i += 1) { @@ -1104,10 +1100,9 @@ comparison.oCommentManager.checkComments(arrMainComments, arrRevisedComments, arrMainComments); } }; - CNode.prototype.getArrOfInsertsFromChanges = function (idxOfChange, comparison) { - const oChange = this.changes[idxOfChange]; + CNode.prototype.getArrOfInsertsFromChanges = function (oChange, comparison) { const aContentToInsert = []; - this.checkCommentsFromInsert(idxOfChange, comparison); + this.checkCommentsFromInsert(oChange, comparison); if(oChange.insert.length > 0) { @@ -1116,16 +1111,16 @@ const oFirstText = oFirstNode.getContentElement(true); const oLastText = oLastNode.getContentElement(); - const posLastRunOfInsert = this.cleanEndOfInsert(aContentToInsert, idxOfChange, comparison); + const posLastRunOfInsert = this.cleanEndOfInsert(aContentToInsert, oChange, comparison); // изменения находятся внутри одного рана или это один и тот же элемент if(oFirstText === oLastText) { - this.cleanStartOfInsertSameRun(aContentToInsert[aContentToInsert.length - 1], idxOfChange); + this.cleanStartOfInsertSameRun(aContentToInsert[aContentToInsert.length - 1], oChange); } else { - this.cleanStartOfInsertDifferentRun(aContentToInsert, posLastRunOfInsert, idxOfChange, comparison); + this.cleanStartOfInsertDifferentRun(aContentToInsert, posLastRunOfInsert, oChange, comparison); } const arrStartBookmarks = oFirstNode.getFirstBookmarks(); @@ -1145,12 +1140,11 @@ }; - CNode.prototype.applyInsertsToParagraph = function (comparison, aContentToInsert, idxOfChange) { - const oChange = this.changes[idxOfChange]; + CNode.prototype.applyInsertsToParagraph = function (comparison, aContentToInsert, oChange) { if (oChange.remove.length > 0 && !comparison.isSkipWhitespaces(oChange.remove)) { - this.applyInsertsToParagraphsWithRemove(comparison, aContentToInsert, idxOfChange); + this.applyInsertsToParagraphsWithRemove(comparison, aContentToInsert, oChange); } else { - this.applyInsertsToParagraphsWithoutRemove(comparison, aContentToInsert, idxOfChange); + this.applyInsertsToParagraphsWithoutRemove(comparison, aContentToInsert, oChange); } }; @@ -1158,8 +1152,7 @@ return 0; }; - CNode.prototype.applyInsertsToParagraphsWithoutRemove = function (comparison, aContentToInsert, idxOfChange) { - const oChange = this.changes[idxOfChange]; + CNode.prototype.applyInsertsToParagraphsWithoutRemove = function (comparison, aContentToInsert, oChange) { const applyingParagraph = this.getApplyParagraph(comparison); if(aContentToInsert.length > 0) @@ -1239,8 +1232,7 @@ element.SetReviewTypeWithInfo(reviewtype_Common, info); }; - CNode.prototype.prepareEndOfRemoveChange = function (idxOfChange, comparison, arrSetRemove) { - const oChange = this.changes[idxOfChange]; + CNode.prototype.prepareEndOfRemoveChange = function (oChange, comparison, arrSetRemove) { const oApplyParagraph = this.getApplyParagraph(comparison); const oNode = oChange.remove[oChange.remove.length - 1]; const oLastText = oNode.element; @@ -1285,9 +1277,8 @@ return {posLastRunInContent: k, nInsertPosition: nInsertPosition }; }; - CNode.prototype.setReviewTypeForRemoveChanges = function (comparison, idxOfChange, posLastRunInContent, nInsertPosition, arrSetRemoveReviewType) { + CNode.prototype.setReviewTypeForRemoveChanges = function (comparison, oChange, posLastRunInContent, nInsertPosition, arrSetRemoveReviewType) { const oApplyParagraph = this.getApplyParagraph(comparison); - const oChange = this.changes[idxOfChange]; const oNode = oChange.remove[0]; const oFirstText = oNode.element; const oStartOfRemoveRun = oNode.getContentElement(true); @@ -1341,14 +1332,13 @@ this.insertContentAfterRemoveChanges(arrToInsert, nInsertPosition, comparison, options); }; - CNode.prototype.applyInsertsToParagraphsWithRemove = function (comparison, aContentToInsert, idxOfChange) { + CNode.prototype.applyInsertsToParagraphsWithRemove = function (comparison, aContentToInsert, oChange) { const arrSetRemoveReviewType = []; - const infoAboutEndOfRemoveChange = this.prepareEndOfRemoveChange(idxOfChange, comparison, arrSetRemoveReviewType); + const infoAboutEndOfRemoveChange = this.prepareEndOfRemoveChange(oChange, comparison, arrSetRemoveReviewType); const posLastRunInContent = infoAboutEndOfRemoveChange.posLastRunInContent; let nInsertPosition = infoAboutEndOfRemoveChange.nInsertPosition; - nInsertPosition = this.setReviewTypeForRemoveChanges(comparison, idxOfChange, posLastRunInContent, nInsertPosition, arrSetRemoveReviewType); - const oChange = this.changes[idxOfChange]; + nInsertPosition = this.setReviewTypeForRemoveChanges(comparison, oChange, posLastRunInContent, nInsertPosition, arrSetRemoveReviewType); if (!comparison.options.words && !comparison.isWordsByOneSymbol && oChange.insert.length === 1 && oChange.remove.length === 1) { comparison.resolveConflicts(aContentToInsert, arrSetRemoveReviewType, this.getApplyParagraph(comparison), arrSetRemoveReviewType[arrSetRemoveReviewType.length - 1].GetPosInParent(), true); } else { @@ -2073,41 +2063,48 @@ } return !this.oCommentManager.savedParaComments[oParaComment.Id]; } + function getMockDocumentFromRuns(arrRuns) { + const arrSlice = arrRuns.slice(); + arrSlice.push(new AscCommonWord.ParaRun()); + arrSlice[arrSlice.length - 1].Content.push(new AscWord.CRunParagraphMark()); + + const mockDocument = new AscCommonWord.CMockDocument(); + const mockParagraph = new AscCommonWord.CMockParagraph(); + mockDocument.Content.push(mockParagraph); + mockParagraph.Content = arrSlice; + + return mockDocument; + } + CDocumentComparison.prototype.executeResolveConflictMode = function (oResolveConflictComparison, fCallback) { + const oOldCommentsMeeting = this.oCommentManager.mapCommentMeeting; + this.oCommentManager.mapCommentMeeting = {}; + oResolveConflictComparison.oCommentManager = this.oCommentManager; + + const oOldBookmarkMeeting = this.oBookmarkManager.mapBookmarkMeeting; + this.oBookmarkManager.mapBookmarkMeeting = {}; + oResolveConflictComparison.oBookmarkManager = this.oBookmarkManager; + oResolveConflictComparison.oComparisonMoveMarkManager = this.oComparisonMoveMarkManager; + oResolveConflictComparison.CommentsMap = this.CommentsMap; + oResolveConflictComparison.StylesMap = this.StylesMap; + fCallback(); + this.oBookmarkManager.mapBookmarkMeeting = oOldBookmarkMeeting; + this.oCommentManager.mapCommentMeeting = oOldCommentsMeeting; + }; CDocumentComparison.prototype.resolveConflicts = function(arrToInserts, arrToRemove, applyParagraph, nInsertPosition, bIsWordsByOneSymbol) { if (arrToInserts.length === 0 || arrToRemove.length === 0) return; - arrToRemove.push(new AscCommonWord.ParaRun()); - arrToInserts.push(new AscCommonWord.ParaRun()); - arrToRemove[arrToRemove.length - 1].Content.push(new AscWord.CRunParagraphMark()); - arrToInserts[arrToInserts.length - 1].Content.push(new AscWord.CRunParagraphMark()); const comparison = new AscCommonWord.CDocumentResolveConflictComparison(this.originalDocument, this.revisedDocument, this.options, bIsWordsByOneSymbol); - const oOldCommentsMeeting = this.oCommentManager.mapCommentMeeting; - this.oCommentManager.mapCommentMeeting = {}; - comparison.oCommentManager = this.oCommentManager; - - const oOldBookmarkMeeting = this.oBookmarkManager.mapBookmarkMeeting; - this.oBookmarkManager.mapBookmarkMeeting = {}; - comparison.oBookmarkManager = this.oBookmarkManager; - comparison.oComparisonMoveMarkManager = this.oComparisonMoveMarkManager; - comparison.CommentsMap = this.CommentsMap; - comparison.StylesMap = this.StylesMap; - const originalDocument = new AscCommonWord.CMockDocument(); - const revisedDocument = new AscCommonWord.CMockDocument(); - const originalParagraph = new AscCommonWord.CMockParagraph(); - const revisedParagraph = new AscCommonWord.CMockParagraph(); - const origParagraph = applyParagraph; - comparison.startPosition = nInsertPosition; - comparison.parentParagraph = origParagraph; - originalParagraph.Content = arrToRemove; - revisedParagraph.Content = arrToInserts; - originalDocument.Content.push(originalParagraph); - revisedDocument.Content.push(revisedParagraph); - - comparison.oComparisonMoveMarkManager.executeResolveConflictMode(function () { - comparison.compareRoots(originalDocument, revisedDocument); + this.executeResolveConflictMode(comparison, function () { + const originalDocument = getMockDocumentFromRuns(arrToRemove); + const revisedDocument = getMockDocumentFromRuns(arrToInserts); + const origParagraph = applyParagraph; + comparison.startPosition = nInsertPosition; + comparison.parentParagraph = origParagraph; + + comparison.oComparisonMoveMarkManager.executeResolveConflictMode(function () { + comparison.compareRoots(originalDocument, revisedDocument); + }); }); - this.oBookmarkManager.mapBookmarkMeeting = oOldBookmarkMeeting; - this.oCommentManager.mapCommentMeeting = oOldCommentsMeeting; }; CDocumentComparison.prototype.checkOriginalAndSplitRun = function (oOriginalRun, oSplitRun) { @@ -2631,9 +2628,9 @@ resolveTypesWithPartner(arrResult, this); } this.executeWithCheckInsertAndRemove(function () { - const aContentToInsert = this.isSkipWhitespaces(oChange.insert) ? [] : oNode.getArrOfInsertsFromChanges(i, this); + const aContentToInsert = this.isSkipWhitespaces(oChange.insert) ? [] : oNode.getArrOfInsertsFromChanges(oChange, this); //handle removed elements - oNode.applyInsertsToParagraph(this, aContentToInsert, i); + oNode.applyInsertsToParagraph(this, aContentToInsert, oChange); }.bind(this), oChange); nLastIndex = oChange.anchor.index - 1; @@ -3652,10 +3649,6 @@ oLogicDocument.LoadDocumentState(oSelectionState); }; - window['AscCommonWord'] = window['AscCommonWord'] || {}; - window['AscCommonWord'].CDocumentComparison = CDocumentComparison; - window['AscCommonWord'].ComparisonOptions = window['AscCommonWord']["ComparisonOptions"] = ComparisonOptions; - function CompareBinary(oApi, sBinary2, oOptions, bForceApplyChanges) { const oDoc1 = oApi.WordControl.m_oLogicDocument; diff --git a/word/Editor/Merge.js b/word/Editor/Merge.js index 10f3efc5f3..0dce75c200 100644 --- a/word/Editor/Merge.js +++ b/word/Editor/Merge.js @@ -55,13 +55,13 @@ CMergeComparisonNode.prototype = Object.create(CNode.prototype); CMergeComparisonNode.prototype.constructor = CMergeComparisonNode; - CMergeComparisonNode.prototype.applyInsertsToParagraphsWithRemove = function(comparison, aContentToInsert, idxOfChange) { + CMergeComparisonNode.prototype.applyInsertsToParagraphsWithRemove = function(comparison, aContentToInsert, oChange) { const arrSetRemoveReviewType = []; - const infoAboutEndOfRemoveChange = this.prepareEndOfRemoveChange(idxOfChange, comparison, arrSetRemoveReviewType); + const infoAboutEndOfRemoveChange = this.prepareEndOfRemoveChange(oChange, comparison, arrSetRemoveReviewType); const posLastRunInContent = infoAboutEndOfRemoveChange.posLastRunInContent; let nInsertPosition = infoAboutEndOfRemoveChange.nInsertPosition; - nInsertPosition = this.setReviewTypeForRemoveChanges(comparison, idxOfChange, posLastRunInContent, nInsertPosition, arrSetRemoveReviewType); + nInsertPosition = this.setReviewTypeForRemoveChanges(comparison, oChange, posLastRunInContent, nInsertPosition, arrSetRemoveReviewType); this.applyInsert(aContentToInsert, arrSetRemoveReviewType, nInsertPosition, comparison, {needReverse: true}); }; @@ -74,11 +74,6 @@ return CNode.prototype.privateCompareElements.call(this, oNode, bCheckNeighbors, oComparison); } - CMergeComparisonNode.prototype.copyRunWithMockParagraph = function (oRun, mockParagraph, comparison) { - const oRet = CNode.prototype.copyRunWithMockParagraph.call(this, oRun, mockParagraph, comparison); - return oRet; - }; - CMergeComparisonNode.prototype.setCommonReviewTypeWithInfo = function (element, info) { element.SetReviewTypeWithInfo((element.GetReviewType && element.GetReviewType()) || reviewtype_Common, info); }; @@ -286,8 +281,18 @@ oMainTextElement = other; oSecondaryTextElement = this; } - const bCheckStart = oMainTextElement.isWordBeginWith(oSecondaryTextElement); - const bCheckEnd = oMainTextElement.isWordEndWith(oSecondaryTextElement); + let bCheckStart = false; + let bCheckEnd = false; + const nEndIndex = oSecondaryTextElement.elements.length - 1; + const oEndElement = oMainTextElement.elements[nEndIndex]; + if (oMainTextElement.checkRemoveReviewType(nEndIndex) || AscCommon.isEastAsianScript(oEndElement.Value)) { + bCheckStart = oMainTextElement.isWordBeginWith(oSecondaryTextElement); + } + const nStartIndex = oMainTextElement.elements.length - oSecondaryTextElement.elements.length; + const oStartElement = oMainTextElement.elements[nStartIndex]; + if (oMainTextElement.checkRemoveReviewType(nStartIndex) || AscCommon.isEastAsianScript(oStartElement.Value)) { + bCheckEnd = oMainTextElement.isWordEndWith(oSecondaryTextElement); + } return bCheckStart || bCheckEnd; }; @@ -378,15 +383,14 @@ const oChildNode = oNode.children[i]; if (i !== oNode.children.length - 1) { if (oChildNode.partner && oChildNode.element instanceof CTextElement) { - oChildNode.tryUpdateNode(this); - oChildNode.resolveTypesWithPartner(this); + oChildNode.updateEqualNode(this, i); } } const oChange = oNode.changes[currentChangeId]; if (oChange && oChange.anchor.index === i) { - const aContentToInsert = this.isSkipWhitespaces(oChange.insert) ? [] : oNode.getArrOfInsertsFromChanges(currentChangeId, this); // todo: check skip on symbol comparing + const aContentToInsert = this.isSkipWhitespaces(oChange.insert) ? [] : oNode.getArrOfInsertsFromChanges(oChange, this); // todo: check skip on symbol comparing //handle removed elements - oNode.applyInsertsToParagraph(this, aContentToInsert, currentChangeId); + oNode.applyInsertsToParagraph(this, aContentToInsert, oChange); currentChangeId += 1 } if (oChange && oChange.anchor.index > i) { @@ -485,16 +489,15 @@ CConflictResolveNode.prototype = Object.create(CNode.prototype); CConflictResolveNode.prototype.constructor = CConflictResolveNode; - CConflictResolveNode.prototype.applyInsertsToParagraphsWithRemove = function (comparison, aContentToInsert, idxOfChange) { + CConflictResolveNode.prototype.applyInsertsToParagraphsWithRemove = function (comparison, aContentToInsert, oChange) { const arrSetRemoveReviewType = []; - const infoAboutEndOfRemoveChange = this.prepareEndOfRemoveChange(idxOfChange, comparison, arrSetRemoveReviewType); + const infoAboutEndOfRemoveChange = this.prepareEndOfRemoveChange(oChange, comparison, arrSetRemoveReviewType); const posLastRunInContent = infoAboutEndOfRemoveChange.posLastRunInContent; const nInsertPosition = infoAboutEndOfRemoveChange.nInsertPosition; - this.setReviewTypeForRemoveChanges(comparison, idxOfChange, posLastRunInContent, nInsertPosition, arrSetRemoveReviewType); + this.setReviewTypeForRemoveChanges(comparison, oChange, posLastRunInContent, nInsertPosition, arrSetRemoveReviewType); const nInsertPosition2 = arrSetRemoveReviewType[arrSetRemoveReviewType.length - 1].GetPosInParent(); - const oChange = this.changes[idxOfChange]; if (!comparison.options.words && !comparison.isWordsByOneSymbol && oChange.insert.length === 1 && oChange.remove.length === 1) { aContentToInsert.reverse(); arrSetRemoveReviewType.reverse(); @@ -503,150 +506,30 @@ this.applyInsert(aContentToInsert, arrSetRemoveReviewType, nInsertPosition2, comparison, {needReverse: true, nCommentInsertIndex: nInsertPosition}); } }; - - // обновим ноды в любом случае, для дальнейшего разрешения типов - CConflictResolveNode.prototype.tryUpdateNode = function (comparison) { - const oPartnerNode = this.partner; - if (oPartnerNode) - { - let oSplitRun; - const oOriginalTextElement = this.element; - const oPartnerTextElement = oPartnerNode.element; - if (oPartnerTextElement.elements.length > oOriginalTextElement.elements.length) { - const oNewOriginalTextElement = new CResolveConflictTextElement(); - oNewOriginalTextElement.firstRun = oOriginalTextElement.firstRun; - oNewOriginalTextElement.lastRun = oOriginalTextElement.lastRun; - - const bIsWordBeginWithText = oPartnerTextElement.isWordBeginWith(oOriginalTextElement); - const bIsWordEndWithText = oPartnerTextElement.isWordEndWith(oOriginalTextElement); - - const oParent = oOriginalTextElement.lastRun.GetParent(); - const oMainMockParagraph = this.par.element; - if (bIsWordBeginWithText) { - for (let i = 0; i < oOriginalTextElement.elements.length; i += 1) { - oNewOriginalTextElement.addToElements(oOriginalTextElement.elements[i], oOriginalTextElement.reviewElementTypes[i]); - } - } - let nPreviousRunPosition; - if (bIsWordBeginWithText || bIsWordEndWithText) { - this.element = oNewOriginalTextElement; - const oMockParagraph = oPartnerNode.par.element; - let nAmountOfAddingElements = oPartnerTextElement.elements.length - oOriginalTextElement.elements.length; - let nCurrentRunPosition = oPartnerTextElement.lastRun.GetPosInParent(oMockParagraph); - let oCurrentRun = oMockParagraph.Content[nCurrentRunPosition]; - let nLastPartnerElementPosition = oCurrentRun.GetElementPosition(oPartnerTextElement.elements[oPartnerTextElement.elements.length - 1]); - - if (bIsWordEndWithText) { - let nOffset = oOriginalTextElement.elements.length; - while (nOffset) { - if (nOffset - oCurrentRun.Content.length <= 0) { - nLastPartnerElementPosition = oCurrentRun.Content.length - nOffset - 1; - break; - } - nOffset -= oCurrentRun.Content.length; - nCurrentRunPosition -= 1; - oCurrentRun = oMockParagraph.Content[nCurrentRunPosition]; - } - } else { - nLastPartnerElementPosition = oCurrentRun.GetElementPosition(oPartnerTextElement.elements[oPartnerTextElement.elements.length - 1]); - } - oSplitRun = oCurrentRun.Split2(nLastPartnerElementPosition + 1); - oMockParagraph.Add_ToContent(nCurrentRunPosition + 1, oSplitRun); - const arrContentForInsert = []; - while (nAmountOfAddingElements) { - const oReviewInfo = comparison.getCompareReviewInfo(oCurrentRun); - for (let i = oCurrentRun.Content.length - 1; i >= 0; i -= 1) { - nAmountOfAddingElements -= 1; - if (nAmountOfAddingElements === 0 && i !== 0) { - oCurrentRun = oCurrentRun.Split2(i); - oMockParagraph.Add_ToContent(nCurrentRunPosition + 1, oCurrentRun); - break; - } - } - const oCopyCurrentRun = oCurrentRun.Copy(false, {CopyReviewPr: true}); - for (let i = 0; i < oCopyCurrentRun.Content.length; i += 1) { - oNewOriginalTextElement.addToElements(oCopyCurrentRun.Content[i], oReviewInfo); - } - arrContentForInsert.push(oCopyCurrentRun); - nCurrentRunPosition -= 1; - oCurrentRun = oMockParagraph.Content[nCurrentRunPosition]; - } - let nLastOriginalElementPosition; - let nLastRunPosition; - let nMockRunPosition; - if (bIsWordBeginWithText) { - nLastRunPosition = oOriginalTextElement.lastRun.GetPosInParent(); - nMockRunPosition = oOriginalTextElement.lastRun.GetPosInParent(oMainMockParagraph); - oNewOriginalTextElement.lastRun = arrContentForInsert[0]; - nLastOriginalElementPosition = oParent.Content[nLastRunPosition].GetElementPosition(oOriginalTextElement.elements[oOriginalTextElement.elements.length - 1]); - oSplitRun = oParent.Content[nLastRunPosition].Split2(nLastOriginalElementPosition + 1, oParent, nLastRunPosition) - oMainMockParagraph.Add_ToContent(nLastRunPosition + 1, oSplitRun); - } else { - nLastRunPosition = oOriginalTextElement.firstRun.GetPosInParent(); - nMockRunPosition = oOriginalTextElement.firstRun.GetPosInParent(oMainMockParagraph); - nPreviousRunPosition = nLastRunPosition + arrContentForInsert.length; - nLastOriginalElementPosition = oParent.Content[nLastRunPosition].GetElementPosition(oOriginalTextElement.elements[0]); - oSplitRun = oParent.Content[nLastRunPosition].Split2(nLastOriginalElementPosition, oParent, nLastRunPosition); - oMainMockParagraph.Add_ToContent(nMockRunPosition + 1, oSplitRun); - oNewOriginalTextElement.firstRun = arrContentForInsert[0]; - } - - for (let i = 0; i < arrContentForInsert.length; i += 1) { - oParent.Add_ToContent(nLastRunPosition + 1, arrContentForInsert[i]); - oMainMockParagraph.Add_ToContent(nMockRunPosition + 1, arrContentForInsert[i]); - } - } - - if (bIsWordEndWithText && !bIsWordBeginWithText) { - let nElementsAmount = oOriginalTextElement.elements.length; - let nCurrentRunPosition = nPreviousRunPosition + 1; - let oCurrentRun = oParent.Content[nCurrentRunPosition]; - while (nElementsAmount) { - const oReviewInfo = comparison.getCompareReviewInfo(oCurrentRun); - oNewOriginalTextElement.lastRun = oCurrentRun; - for (let i = 0; i < oCurrentRun.Content.length; i += 1) { - oNewOriginalTextElement.addToElements(oCurrentRun.Content[i], oReviewInfo); - nElementsAmount -= 1; - if (nElementsAmount === 0) - { - break; - } - } - nCurrentRunPosition += 1; - oCurrentRun = oParent.Content[nCurrentRunPosition]; - } - } - } else if (oPartnerTextElement.elements.length < oOriginalTextElement.elements.length) { - // здесь мы просто выравниваем количество элементов в ноде, чтобы разрешить остатки типов - const bIsWordBeginWithText = oOriginalTextElement.isWordBeginWith(oPartnerTextElement); - const bIsWordEndWithText = oOriginalTextElement.isWordEndWith(oPartnerTextElement); - const oNewPartnerTextElement = new CResolveConflictTextElement(); - oNewPartnerTextElement.lastRun = oPartnerTextElement.lastRun; - oNewPartnerTextElement.firstRun = oPartnerTextElement.firstRun; - oPartnerNode.element = oNewPartnerTextElement; - if (bIsWordBeginWithText) { - for (let i = 0; i < oPartnerTextElement.elements.length; i += 1) { - oNewPartnerTextElement.addToElements(oPartnerTextElement.elements[i], oPartnerTextElement.reviewElementTypes[[i]]); - } - for (let i = oPartnerTextElement.elements.length; i < oOriginalTextElement.elements.length; i += 1) { - oNewPartnerTextElement.addToElements(oOriginalTextElement.elements[i], oOriginalTextElement.reviewElementTypes[[i]]); - } - } else if (bIsWordEndWithText) { - for (let i = 0; i < (oOriginalTextElement.elements.length - oPartnerTextElement.elements.length); i += 1) { - oNewPartnerTextElement.addToElements(oOriginalTextElement.elements[i], oOriginalTextElement.reviewElementTypes[[i]]); - } - for (let i = 0; i < oPartnerTextElement.elements.length; i += 1) { - oNewPartnerTextElement.addToElements(oPartnerTextElement.elements[i], oPartnerTextElement.reviewElementTypes[[i]]); - } - } - } - } - }; - - CConflictResolveNode.prototype.applyInsertsToParagraphsWithoutRemove = function (comparison, aContentToInsert, idxOfChange) { - const bRet = CNode.prototype.applyInsertsToParagraphsWithoutRemove.call(this, comparison, aContentToInsert, idxOfChange); + CConflictResolveNode.prototype.updateEqualNode = function (comparison, index) { + const oPartnerNode = this.partner; + const oOriginalTextElement = this.element; + const oPartnerTextElement = oPartnerNode.element; + if (oPartnerTextElement.elements.length === oOriginalTextElement.elements.length) { + this.resolveTypesWithPartner(comparison); + } else { + const oParentNode = this.par; + const oChange = new AscCommon.AttachedOperation( + new AscCommon.Anchor(oParentNode, oParentNode, index), + AscCommon.UPDATE_FOREST_TYPE, [index], + [this], [oPartnerNode]); + const bOldComparisonWordOption = comparison.options.words; + comparison.options.words = false; + comparison.copyPr.SkipUpdateInfo = true; + const aContentToInsert = comparison.isSkipWhitespaces(oChange.insert) ? [] : oParentNode.getArrOfInsertsFromChanges(oChange, comparison); // todo: check skip on symbol comparing + oParentNode.applyInsertsToParagraph(comparison, aContentToInsert, oChange); + comparison.options.words = bOldComparisonWordOption; + comparison.copyPr.SkipUpdateInfo = false; + } + }; + CConflictResolveNode.prototype.applyInsertsToParagraphsWithoutRemove = function (comparison, aContentToInsert, oChange) { + const bRet = CNode.prototype.applyInsertsToParagraphsWithoutRemove.call(this, comparison, aContentToInsert, oChange); if (!bRet) { - const oChange = this.changes[idxOfChange]; const applyingParagraph = this.getApplyParagraph(comparison); const index = oChange.anchor.index; if (index === this.children.length - 1) {