@@ -52,8 +52,6 @@ const getStringTruncatedWidth = ( input: string, truncationOptions: TruncationOp
5252 let truncationEnabled = false ;
5353 let truncationIndex = length ;
5454 let truncationLimit = Math . max ( 0 , LIMIT - ELLIPSIS_WIDTH ) ;
55- let unmatchedStart = 0 ;
56- let unmatchedEnd = 0 ;
5755 let width = 0 ;
5856 let widthExtra = 0 ;
5957
@@ -64,9 +62,9 @@ const getStringTruncatedWidth = ( input: string, truncationOptions: TruncationOp
6462
6563 /* UNMATCHED */
6664
67- if ( ( unmatchedEnd > unmatchedStart ) || ( index >= length && index > indexPrev ) ) {
65+ if ( index > indexPrev ) {
6866
69- const unmatched = input . slice ( unmatchedStart , unmatchedEnd ) || input . slice ( indexPrev , index ) ;
67+ const unmatched = input . slice ( indexPrev , index ) ;
7068
7169 lengthExtra = 0 ;
7270
@@ -83,7 +81,7 @@ const getStringTruncatedWidth = ( input: string, truncationOptions: TruncationOp
8381 }
8482
8583 if ( ( width + widthExtra ) > truncationLimit ) {
86- truncationIndex = Math . min ( truncationIndex , Math . max ( unmatchedStart , indexPrev ) + lengthExtra ) ;
84+ truncationIndex = Math . min ( truncationIndex , indexPrev + lengthExtra ) ;
8785 }
8886
8987 if ( ( width + widthExtra ) > LIMIT ) {
@@ -96,7 +94,7 @@ const getStringTruncatedWidth = ( input: string, truncationOptions: TruncationOp
9694
9795 }
9896
99- unmatchedStart = unmatchedEnd = 0 ;
97+ indexPrev = index ;
10098
10199 }
102100
@@ -129,8 +127,6 @@ const getStringTruncatedWidth = ( input: string, truncationOptions: TruncationOp
129127 }
130128
131129 width += widthExtra ;
132- unmatchedStart = indexPrev ;
133- unmatchedEnd = index ;
134130 index = indexPrev = BLOCK_RE . lastIndex ;
135131
136132 continue outer;
@@ -141,7 +137,7 @@ const getStringTruncatedWidth = ( input: string, truncationOptions: TruncationOp
141137
142138 /* UNMATCHED INDEX */
143139
144- index += 1 ;
140+ index += ( input . codePointAt ( index ) || 0 ) > 0xffff ? 2 : 1 ;
145141
146142 }
147143
0 commit comments