@@ -455,25 +455,36 @@ export const updateHTML = (props: UpdateHTMLProps): { updatedHTML: string; updat
455455 break ;
456456 } else if ( startIndex > tag . plainTextBeginIndex && oldPlainTextEndIndex > closingTagInfo . plainTextEndIndex ) {
457457 // the change started in the tag but finishes somewhere further
458- const startChangeDiff = startIndex - tag . plainTextBeginIndex - mentionTagLength ;
459458 if ( isMentionTag ) {
460- const updateMentionTagResult = handleMentionTagUpdate ( {
461- htmlText,
462- oldPlainText,
463- lastProcessedHTMLIndex,
464- processedChange : '' ,
465- change,
466- tag,
467- closeTagIdx : closingTagInfo . closeTagIdx ,
468- closeTagLength : closingTagInfo . closeTagLength ,
469- plainTextEndIndex : closingTagInfo . plainTextEndIndex ,
470- startIndex,
471- oldPlainTextEndIndex,
472- mentionTagLength
473- } ) ;
474- result += updateMentionTagResult . result ;
475- lastProcessedHTMLIndex = updateMentionTagResult . htmlIndex ;
476- // no need to handle plainTextSelectionEndIndex as the change will be added later
459+ if ( startIndex === closingTagInfo . plainTextEndIndex ) {
460+ // the change should be handled out of mention tag
461+ // as startIndex === closingTagInfo.plainTextEndIndex and oldPlainTextEndIndex > closingTagInfo.plainTextEndIndex
462+ result += htmlText . substring (
463+ lastProcessedHTMLIndex ,
464+ closingTagInfo . closeTagIdx + closingTagInfo . closeTagLength
465+ ) ;
466+ // no need to handle plainTextSelectionEndIndex as the change will be added later
467+ lastProcessedHTMLIndex = closingTagInfo . closeTagIdx + closingTagInfo . closeTagLength ;
468+ } else {
469+ // part of the mention tag was changed/deleted
470+ const updateMentionTagResult = handleMentionTagUpdate ( {
471+ htmlText,
472+ oldPlainText,
473+ lastProcessedHTMLIndex,
474+ processedChange : '' ,
475+ change,
476+ tag,
477+ closeTagIdx : closingTagInfo . closeTagIdx ,
478+ closeTagLength : closingTagInfo . closeTagLength ,
479+ plainTextEndIndex : closingTagInfo . plainTextEndIndex ,
480+ startIndex,
481+ oldPlainTextEndIndex,
482+ mentionTagLength
483+ } ) ;
484+ result += updateMentionTagResult . result ;
485+ lastProcessedHTMLIndex = updateMentionTagResult . htmlIndex ;
486+ // no need to handle plainTextSelectionEndIndex as the change will be added later
487+ }
477488 } else if ( tag . subTags !== undefined && tag . subTags . length !== 0 && tag . content !== undefined ) {
478489 // with subtags
479490 const stringBefore = htmlText . substring ( lastProcessedHTMLIndex , tag . openTagIndex + tag . openTagBody . length ) ;
@@ -490,6 +501,7 @@ export const updateHTML = (props: UpdateHTMLProps): { updatedHTML: string; updat
490501 result += stringBefore + updatedContent . updatedHTML ;
491502 } else {
492503 // no subtags
504+ const startChangeDiff = startIndex - tag . plainTextBeginIndex - mentionTagLength ;
493505 result += htmlText . substring (
494506 lastProcessedHTMLIndex ,
495507 tag . openTagIndex + tag . openTagBody . length + startChangeDiff
0 commit comments