@@ -45,8 +45,6 @@ const getStringTruncatedWidth = ( input: string, truncationOptions: TruncationOp
4545  let  truncationEnabled  =  false ; 
4646  let  truncationIndex  =  length ; 
4747  let  truncationLimit  =  Math . max  (  0 ,  LIMIT  -  ELLIPSIS_WIDTH  ) ; 
48-   let  unmatchedStart  =  0 ; 
49-   let  unmatchedEnd  =  0 ; 
5048  let  width  =  0 ; 
5149  let  widthExtra  =  0 ; 
5250
@@ -57,9 +55,9 @@ const getStringTruncatedWidth = ( input: string, truncationOptions: TruncationOp
5755
5856    /* UNMATCHED */ 
5957
60-     if  (  (   unmatchedEnd   >   unmatchedStart   )   ||   (   index  >=    length   &&   index   >   indexPrev   )  )  { 
58+     if  (  index  >   indexPrev  )  { 
6159
62-       const  unmatched  =  input . slice  (  unmatchedStart ,   unmatchedEnd   )   ||   input . slice   (   indexPrev ,  index  ) ; 
60+       const  unmatched  =  input . slice  (  indexPrev ,  index  ) ; 
6361
6462      lengthExtra  =  0 ; 
6563
@@ -78,7 +76,7 @@ const getStringTruncatedWidth = ( input: string, truncationOptions: TruncationOp
7876        } 
7977
8078        if  (  (  width  +  widthExtra  )  >  truncationLimit  )  { 
81-           truncationIndex  =  Math . min  (  truncationIndex ,  Math . max   (   unmatchedStart ,   indexPrev   )  +  lengthExtra  ) ; 
79+           truncationIndex  =  Math . min  (  truncationIndex ,  indexPrev  +  lengthExtra  ) ; 
8280        } 
8381
8482        if  (  (  width  +  widthExtra  )  >  LIMIT  )  { 
@@ -91,8 +89,7 @@ const getStringTruncatedWidth = ( input: string, truncationOptions: TruncationOp
9189
9290      } 
9391
94-       unmatchedStart  =  unmatchedEnd  =  0 ; 
95- 
92+       indexPrev  =  index ; 
9693    } 
9794
9895    /* EXITING */ 
@@ -118,8 +115,6 @@ const getStringTruncatedWidth = ( input: string, truncationOptions: TruncationOp
118115      } 
119116
120117      width  +=  widthExtra ; 
121-       unmatchedStart  =  indexPrev ; 
122-       unmatchedEnd  =  index ; 
123118      index  =  indexPrev  =  LATIN_RE . lastIndex ; 
124119
125120      continue ; 
@@ -142,8 +137,6 @@ const getStringTruncatedWidth = ( input: string, truncationOptions: TruncationOp
142137      } 
143138
144139      width  +=  ANSI_WIDTH ; 
145-       unmatchedStart  =  indexPrev ; 
146-       unmatchedEnd  =  index ; 
147140      index  =  indexPrev  =  ANSI_RE . lastIndex ; 
148141
149142      continue ; 
@@ -169,8 +162,6 @@ const getStringTruncatedWidth = ( input: string, truncationOptions: TruncationOp
169162      } 
170163
171164      width  +=  widthExtra ; 
172-       unmatchedStart  =  indexPrev ; 
173-       unmatchedEnd  =  index ; 
174165      index  =  indexPrev  =  CONTROL_RE . lastIndex ; 
175166
176167      continue ; 
@@ -196,8 +187,6 @@ const getStringTruncatedWidth = ( input: string, truncationOptions: TruncationOp
196187      } 
197188
198189      width  +=  widthExtra ; 
199-       unmatchedStart  =  indexPrev ; 
200-       unmatchedEnd  =  index ; 
201190      index  =  indexPrev  =  TAB_RE . lastIndex ; 
202191
203192      continue ; 
@@ -220,8 +209,6 @@ const getStringTruncatedWidth = ( input: string, truncationOptions: TruncationOp
220209      } 
221210
222211      width  +=  EMOJI_WIDTH ; 
223-       unmatchedStart  =  indexPrev ; 
224-       unmatchedEnd  =  index ; 
225212      index  =  indexPrev  =  EMOJI_RE . lastIndex ; 
226213
227214      continue ; 
@@ -230,8 +217,7 @@ const getStringTruncatedWidth = ( input: string, truncationOptions: TruncationOp
230217
231218    /* UNMATCHED INDEX */ 
232219
233-     index  +=  1 ; 
234- 
220+     index  +=  (  input . codePointAt ( index )  ||  0  )  >  0xffff  ? 2  : 1 ; 
235221  } 
236222
237223  /* RETURN */ 
0 commit comments