File tree Expand file tree Collapse file tree 3 files changed +36
-3
lines changed
Expand file tree Collapse file tree 3 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,11 @@ var AngularRichTextDiff;
1717 } ) ;
1818 this . tagMap = { } ;
1919 this . mapLength = 0 ;
20+ // Go ahead and map nbsp;
21+ var unicodeCharacter = String . fromCharCode ( this . unicodeRangeStart + this . mapLength ) ;
22+ this . tagMap [ ' ' ] = unicodeCharacter ;
23+ this . tagMap [ unicodeCharacter ] = ' ' ;
24+ this . mapLength ++ ;
2025 this . dmp = new diff_match_patch ( ) ;
2126 this . doDiff ( ) ;
2227 }
@@ -33,6 +38,14 @@ var AngularRichTextDiff;
3338 this . $scope . diffOutput = this . $sce . trustAsHtml ( diffOutput ) ;
3439 } ;
3540 RichTextDiffController . prototype . insertTagsForOperation = function ( diffableString , operation ) {
41+ // Don't insert anything if these are all tags
42+ var n = - 1 ;
43+ do {
44+ n ++ ;
45+ } while ( diffableString . charCodeAt ( n ) >= this . unicodeRangeStart ) ;
46+ if ( n + 1 >= diffableString . length ) {
47+ return diffableString ;
48+ }
3649 var openTag = '' ;
3750 var closeTag = '' ;
3851 if ( operation === 1 ) {
@@ -71,6 +84,7 @@ var AngularRichTextDiff;
7184 return outputString ;
7285 } ;
7386 RichTextDiffController . prototype . convertHtmlToDiffableString = function ( htmlString ) {
87+ htmlString = htmlString . replace ( / & n b s p ; / g, this . tagMap [ ' ' ] ) ;
7488 var diffableString = '' ;
7589 var offset = 0 ;
7690 while ( offset < htmlString . length ) {
Original file line number Diff line number Diff line change @@ -25,10 +25,17 @@ module AngularRichTextDiff {
2525 dmp : diff_match_patch ;
2626
2727 constructor ( public $scope : IRichTextDiffScope , public $sce : ng . ISCEService ) {
28- $scope . $watch ( 'left' , ( ) => { this . doDiff ( ) ; } ) ;
29- $scope . $watch ( 'right' , ( ) => { this . doDiff ( ) ; } ) ;
28+ $scope . $watch ( 'left' , ( ) => { this . doDiff ( ) ; } ) ;
29+ $scope . $watch ( 'right' , ( ) => { this . doDiff ( ) ; } ) ;
3030 this . tagMap = { } ;
3131 this . mapLength = 0 ;
32+
33+ // Go ahead and map nbsp;
34+ var unicodeCharacter = String . fromCharCode ( this . unicodeRangeStart + this . mapLength ) ;
35+ this . tagMap [ ' ' ] = unicodeCharacter ;
36+ this . tagMap [ unicodeCharacter ] = ' ' ;
37+ this . mapLength ++ ;
38+
3239 this . dmp = new diff_match_patch ( ) ;
3340 this . doDiff ( ) ;
3441 }
@@ -48,6 +55,17 @@ module AngularRichTextDiff {
4855 }
4956
5057 insertTagsForOperation ( diffableString : string , operation : number ) : string {
58+
59+ // Don't insert anything if these are all tags
60+ var n = - 1 ;
61+ do {
62+ n ++ ;
63+ }
64+ while ( diffableString . charCodeAt ( n ) >= this . unicodeRangeStart ) ;
65+ if ( n + 1 >= diffableString . length ) {
66+ return diffableString ;
67+ }
68+
5169 var openTag = '' ;
5270 var closeTag = '' ;
5371 if ( operation === 1 ) {
@@ -88,6 +106,7 @@ module AngularRichTextDiff {
88106 }
89107
90108 convertHtmlToDiffableString ( htmlString : string ) : string {
109+ htmlString = htmlString . replace ( / & n b s p ; / g, this . tagMap [ ' ' ] ) ;
91110 var diffableString = '' ;
92111
93112 var offset = 0 ;
Original file line number Diff line number Diff line change 11{
22 "name" : " angular-rich-text-diff" ,
33 "main" : " angular-rich-text-diff.js" ,
4- "version" : " 0.2.0 " ,
4+ "version" : " 0.2.1 " ,
55 "authors" : [
66 " Bill Long <bill@blackout.us>"
77 ],
You can’t perform that action at this time.
0 commit comments