11import ContentNode from './ContentNode' ;
2-
32 /**
43 * creates nodes with entity keys and the endOffset
54 */
@@ -62,6 +61,10 @@ function getRelevantIndexes(text, inlineRanges, entityRanges = []) {
6261 return uniqueRelevantIndexes . sort ( ( aa , bb ) => ( aa - bb ) ) ;
6362}
6463
64+ /**
65+ * Slices the decoded ucs2 array and encodes the result back to a string representation
66+ */
67+ const getString = ( array , from , to ) => array . slice ( from , to ) . join ( '' ) ;
6568
6669export default class RawParser {
6770
@@ -91,12 +94,12 @@ export default class RawParser {
9194 ? indexes [ key + 1 ] - index
9295 : 1 ;
9396 // add all the chars up to next relevantIndex
94- const text = this . text . substr ( index , distance ) ;
97+ const text = getString ( this . textArray , index , index + distance ) ;
9598 node . pushContent ( text , characterStyles ) ;
9699
97100 // if thers no next index and thers more text left to push
98101 if ( ! indexes [ key + 1 ] && index < end ) {
99- node . pushContent ( this . text . substring ( index + 1 , end ) , this . relevantStyles ( end - 1 ) ) ;
102+ node . pushContent ( getString ( this . textArray , index + 1 , end ) , this . relevantStyles ( end - 1 ) ) ;
100103 }
101104 } ) ;
102105 return node ;
@@ -108,7 +111,9 @@ export default class RawParser {
108111 * the idea is still mostly same as backdraft.js (https://github.com/evanc/backdraft-js)
109112 */
110113 parse ( { text, inlineStyleRanges : ranges , entityRanges } ) {
111- this . text = text ;
114+ // Some unicode charactes actualy have length of more than 1
115+ // this creates an array of code points using es6 string iterator
116+ this . textArray = Array . from ( text ) ;
112117 this . ranges = ranges ;
113118 this . iterator = 0 ;
114119 // get all the relevant indexes for whole block
0 commit comments