diff --git a/angular-rich-text-diff.js b/angular-rich-text-diff.js index 467c127..120207a 100644 --- a/angular-rich-text-diff.js +++ b/angular-rich-text-diff.js @@ -16,6 +16,7 @@ var AngularRichTextDiff; _this.doDiff(); }); this.tagMap = {}; + this.mapLength = 0; this.dmp = new diff_match_patch(); this.doDiff(); } @@ -92,9 +93,10 @@ var AngularRichTextDiff; var unicodeCharacter = this.tagMap[tagString]; if (unicodeCharacter === undefined) { // Nope, need to map it - unicodeCharacter = String.fromCharCode(this.unicodeRangeStart + this.tagMap.length); + unicodeCharacter = String.fromCharCode(this.unicodeRangeStart + this.mapLength); this.tagMap[tagString] = unicodeCharacter; this.tagMap[unicodeCharacter] = tagString; + this.mapLength++; } // At this point it has been mapped, so now we can use it diffableString += htmlString.substr(offset, tagStart - offset); diff --git a/angular-rich-text-diff.ts b/angular-rich-text-diff.ts index 22d47e5..8cdff96 100644 --- a/angular-rich-text-diff.ts +++ b/angular-rich-text-diff.ts @@ -21,12 +21,14 @@ module AngularRichTextDiff { unicodeRangeStart = 0xE000; tagMap: any; + mapLength: number; dmp: diff_match_patch; constructor(public $scope: IRichTextDiffScope, public $sce: ng.ISCEService) { $scope.$watch('left', () => { this.doDiff(); }); $scope.$watch('right', () => { this.doDiff(); }); this.tagMap = {}; + this.mapLength = 0; this.dmp = new diff_match_patch(); this.doDiff(); } @@ -110,9 +112,10 @@ module AngularRichTextDiff { var unicodeCharacter = this.tagMap[tagString]; if (unicodeCharacter === undefined) { // Nope, need to map it - unicodeCharacter = String.fromCharCode(this.unicodeRangeStart + this.tagMap.length); + unicodeCharacter = String.fromCharCode(this.unicodeRangeStart + this.mapLength); this.tagMap[tagString] = unicodeCharacter; this.tagMap[unicodeCharacter] = tagString; + this.mapLength++; } // At this point it has been mapped, so now we can use it