Skip to content

Commit

Permalink
Develop comment option for comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
Coolcooo committed Jan 15, 2025
1 parent b4b7a9f commit 4f47a00
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 28 deletions.
87 changes: 63 additions & 24 deletions word/Editor/Comparison.js
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,9 @@
};

CNode.prototype.pushToArrInsertContentWithCopy = function (aContentToInsert, elem, comparison) {
if (elem instanceof AscCommon.ParaComment && !comparison.options.comments) {
return;
}
const elemCopy = elem.Copy(false, comparison.copyPr);
this.pushToArrInsertContent(aContentToInsert, elemCopy, comparison);
if (elem instanceof AscCommon.ParaComment)
Expand Down Expand Up @@ -1998,9 +2001,9 @@
this.caseChanges = true;
this.formatting = true;
this.whiteSpace = true;
this.comments = true;

this.comments = true
this.fields = true;
this.fields = true;

this.insertionsAndDeletions = true;
// this.moves = true;
Expand Down Expand Up @@ -2066,6 +2069,12 @@
this.nInsertChangesType = reviewtype_Add;
this.nRemoveChangesType = reviewtype_Remove;
}
CDocumentComparison.prototype.skipCommentElementOnCopyParagraph = function (oParaComment) {
if (this.options.comments) {
return false;
}
return !this.oCommentManager.savedParaComments[oParaComment.Id];
}
CDocumentComparison.prototype.resolveConflicts = function(arrToInserts, arrToRemove, applyParagraph, nInsertPosition, bIsWordsByOneSymbol) {
if (arrToInserts.length === 0 || arrToRemove.length === 0) return;
arrToRemove.push(new AscCommonWord.ParaRun());
Expand Down Expand Up @@ -2426,6 +2435,9 @@
CDocumentComparison.prototype.applyParagraphComparison = function (oOrigRoot, oRevisedRoot) {
const aInsertContent = [];
let nRemoveCount = 0;
this.oCommentManager.generateSavedParaComments();
const bOldSkipFootnoteReference = this.copyPr.SkipFootnoteReference;
this.copyPr.SkipFootnoteReference = false;
for(let i = oOrigRoot.children.length - 1; i > -1 ; --i)
{
if(!oOrigRoot.children[i].partner)
Expand Down Expand Up @@ -2457,6 +2469,7 @@
{
this.insertNodesToDocContent(oOrigRoot.element, nRemoveCount, aInsertContent);
}
this.copyPr.SkipFootnoteReference = bOldSkipFootnoteReference;
};

CDocumentComparison.prototype.compareRoots = function(oRoot1, oRoot2)
Expand Down Expand Up @@ -3514,10 +3527,7 @@
{
this.oBookmarkManager.previousNode = null;
this.oCommentManager.previousNode = null;
const NodeConstructor = this.getNodeConstructor();
const TextElementConstructor = this.getTextElementConstructor();
const oRet = this.createNode(oElement, oParentNode);
const aLastWord = [];
let oLastText = null;
for(let i = 0; i < oElement.Content.length; ++i)
{
Expand All @@ -3533,11 +3543,6 @@
oLastText.updateHash(oWordCounter, this);
this.createNode(oLastText, oRet);
}
if(aLastWord.length > 0)
{
oWordCounter.update(aLastWord, this);
aLastWord.length = 0;
}
oLastText = null;
this.createNode(oRun, oRet);
if (!isOriginalDocument && !this.bSkipChangeMoveType) {
Expand All @@ -3562,16 +3567,28 @@
}
else if (oRun instanceof AscCommon.ParaComment)
{
const oComment = this.getComment(oRun.GetCommentId());
const oElement = new CCommentElement(oComment, oRun);
if (oLastText)
{
this.oCommentManager.addToStack(oElement, oLastText.elements.length);
}
else
{
this.oCommentManager.addToStack(oElement, 0);
if (this.options.comments) {
const oComment = this.getComment(oRun.GetCommentId());
const oElement = new CCommentElement(oComment, oRun);
if (oLastText)
{
this.oCommentManager.addToStack(oElement, oLastText.elements.length);
}
else
{
this.oCommentManager.addToStack(oElement, 0);
}
} else {
this.oCommentManager.addToCheckSaveParaComment(oRun);
}
}
else if (!this.options.fields && (oRun instanceof AscCommonWord.ParaField)) {
if(oLastText && oLastText.elements.length > 0)
{
oLastText.updateHash(oWordCounter, this);
this.createNode(oLastText, oRet);
}
oLastText = null;
}
else
{
Expand All @@ -3580,11 +3597,6 @@
oLastText.updateHash(oWordCounter, this);
this.createNode(oLastText, oRet);
}
if (aLastWord.length > 0)
{
oWordCounter.update(aLastWord, this);
aLastWord.length = 0;
}
oLastText = null;
if (Array.isArray(oRun.Content))
{
Expand Down Expand Up @@ -3940,8 +3952,35 @@
this.mapChecked = {};
this.mapLink = {};
this.mapMergeLater = {};
this.checkSkipParaComment = {};
this.savedParaComments = {};
}

CComparisonCommentManager.prototype.addToCheckSaveParaComment = function (oParaComment) {
const sCommentId = oParaComment.GetCommentId();
if (!this.checkSkipParaComment[sCommentId]) {
this.checkSkipParaComment[sCommentId] = Array(2);
}
if (oParaComment.IsCommentStart()) {
this.checkSkipParaComment[sCommentId][0] = oParaComment;
} else {
this.checkSkipParaComment[sCommentId][1] = oParaComment;
}
};
CComparisonCommentManager.prototype.generateSavedParaComments = function () {
for (let sCommentId in this.checkSkipParaComment) {
const arrParaComments = this.checkSkipParaComment[sCommentId];
const oStartParaComment = arrParaComments[0];
const oEndParaComment = arrParaComments[1];
if (oStartParaComment && oEndParaComment) {
if (oStartParaComment.Paragraph === oEndParaComment.Paragraph && oStartParaComment.Parent === oEndParaComment.Parent) {
this.savedParaComments[oStartParaComment.Id] = true;
this.savedParaComments[oEndParaComment.Id] = true;
}
}
}
this.checkSkipParaComment = {};
}
CComparisonCommentManager.prototype.addToLink = function (sKey, sValue)
{
this.mapLink[sKey] = sValue;
Expand Down
8 changes: 5 additions & 3 deletions word/Editor/Merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@

this.applyInsert(aContentToInsert, arrSetRemoveReviewType, nInsertPosition, comparison, {needReverse: true});
};
CMergeComparisonNode.prototype.privateCompareElements = function (oNode, bCheckNeighbors) {
CMergeComparisonNode.prototype.privateCompareElements = function (oNode, bCheckNeighbors, oComparison) {
const oElement1 = this.element;
const oElement2 = oNode.element;
if (oElement1.isReviewWord !== oElement2.isReviewWord) {
return false;
}
return CNode.prototype.privateCompareElements.call(this, oNode, bCheckNeighbors);
return CNode.prototype.privateCompareElements.call(this, oNode, bCheckNeighbors, oComparison);
}

CMergeComparisonNode.prototype.copyRunWithMockParagraph = function (oRun, mockParagraph, comparison) {
Expand Down Expand Up @@ -302,6 +302,7 @@
this.copyPr = {
CopyReviewPr: false,
Comparison: this,
SkipFootnoteReference: !oOptions.footNotes
};
this.bSaveCustomReviewType = true;
this.isWordsByOneSymbol = !!bIsWordsByOneSymbol;
Expand Down Expand Up @@ -706,7 +707,8 @@
CopyReviewPr: false,
Comparison: this,
SkipUpdateInfo: true,
CheckComparisonMoveMarks: true
CheckComparisonMoveMarks: true,
SkipFootnoteReference: !oOptions.footNotes
};
}

Expand Down
2 changes: 1 addition & 1 deletion word/Editor/Paragraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ Paragraph.prototype.Copy = function(Parent, DrawingDocument, oPr)
{
var Item = this.Content[Index];

if (para_Comment === Item.Type && true === oPr.SkipComments)
if (para_Comment === Item.Type && (true === oPr.SkipComments || oPr.Comparison && oPr.Comparison.skipCommentElementOnCopyParagraph(Item)))
continue;
if (para_Bookmark === Item.Type && true === oPr.SkipBookmarks)
continue;
Expand Down

0 comments on commit 4f47a00

Please sign in to comment.