Multiple comments on one document

Hi,

I am mapping multiple comments to one document utilizing using the method described in this thread:

<A href="</A></P> <P>Here is the behavior that I am seeing. If I have one comment, the comment is correctly mapped to correct word in the document. If I have two comments, both comments are incorrectly mapped to the word associated with the second comment. If I have more that two comments for a document, the first two comments are mapped to the word associated with the second comment, all subsequent comments are correctly mapped to the correct word in the document. Is this a known bug with the doc.Range.Replace method? </P> <P>I appreciate any feedback you can pass along.</P> <P>Here is my code:</P><FONT size=2 face=Consolas><FONT size=2 face=Consolas> <P>doc.Range.Replace(</FONT></FONT><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas><FONT color=#0000ff size=2 face=Consolas>new</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas> </FONT></FONT><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas><FONT color=#2b91af size=2 face=Consolas>Regex</FONT></FONT></FONT><FONT size=2 face=Consolas><FONT size=2 face=Consolas>("regex expression),new ReplaceEvaluatorFindAndComment(nodeRange, commentList, doc), true);

public ReplaceEvaluatorFindAndComment(NodeRange nodeRange, List<Common.DataModel.ReviewersGuide.Comment> commentList, Document doc)
{
NR = nodeRange;
CommentList = commentList;
Doc = doc;
}
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)
{
Node currentNode = e.MatchNode;
if (oldCommentList != CommentList)
{
if (e.MatchOffset > 0)
{
Run afterRun = SplitRun((Run)currentNode, e.MatchOffset);
foreach (Common.DataModel.ReviewersGuide.Comment c in CommentList)
{
oldCommentList = CommentList;
Aspose.Words.Comment comment = new Aspose.Words.Comment(Doc, c.Author, string.Empty, c.Date);
comment.SetText(c.Text);
int commentId = 0;
CommentRangeStart start = new CommentRangeStart(Doc, commentId);
CommentRangeEnd end = new CommentRangeEnd(Doc, commentId);
SplitRun((Run)currentNode, start, end, (Run)afterRun, comment);
}
return ReplaceAction.Replace;
}
else
return ReplaceAction.Skip;
}
else
return ReplaceAction.Replace;
}

private static Run SplitRun(Run run, int position)
{
Run afterRun = (Run)run.Clone(true);
afterRun.Text = run.Text.Substring(position);
run.Text = run.Text.Substring(0, position);
run.ParentNode.InsertAfter(afterRun, run);
return afterRun;
}


private static void SplitRun(Run run, CommentRangeStart start, CommentRangeEnd end, Run afterRun, Aspose.Words.Comment comment)
{
run.ParentNode.InsertBefore(comment, run);
run.ParentNode.InsertBefore(start, run);
afterRun.ParentNode.InsertAfter(end, afterRun);
}

Hi Todd,

Thanks for your inquiry.

Your code appears to be working as expected on my side. Could you please post your template you are using here along with the code you are using to call the replacement. We will take a look into it for you.

Thanks,