File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change 9
9
getStringWidth,
10
10
isFullWidthCodePoint,
11
11
kEscapeCodeTimeout,
12
+ kUTF16SurrogateThreshold,
12
13
moveCursor,
13
14
stripVTControlCharacters
14
15
} = require ( 'internal/readline/utils' ) ;
@@ -1051,8 +1052,8 @@ function charLengthLeft(str, i) {
1051
1052
if ( i <= 0 )
1052
1053
return 0 ;
1053
1054
1054
- if ( i > 1 && str . codePointAt ( i - 2 ) >= 2 ** 16 ||
1055
- str . codePointAt ( i - 1 ) >= 2 ** 16 ) {
1055
+ if ( i > 1 && str . codePointAt ( i - 2 ) >= kUTF16SurrogateThreshold ||
1056
+ str . codePointAt ( i - 1 ) >= kUTF16SurrogateThreshold ) {
1056
1057
return 2 ;
1057
1058
}
1058
1059
@@ -1063,7 +1064,7 @@ function charLengthLeft(str, i) {
1063
1064
function charLengthAt ( str , i ) {
1064
1065
if ( str . length <= i )
1065
1066
return 0 ;
1066
- return str . codePointAt ( i ) >= 2 ** 16 ? 2 : 1 ;
1067
+ return str . codePointAt ( i ) >= kUTF16SurrogateThreshold ? 2 : 1 ;
1067
1068
}
1068
1069
1069
1070
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ const kEscapeCodeTimeout = 500;
17
17
18
18
const kKeypressDecoder = Symbol ( 'keypress-decoder' ) ;
19
19
const kEscapeDecoder = Symbol ( 'escape-decoder' ) ;
20
+ const kUTF16SurrogateThreshold = 0x10000 ; // 2 ** 16
20
21
const kEscape = '\x1b' ;
21
22
22
23
let StringDecoder ; // Lazy loaded.
@@ -72,7 +73,7 @@ if (internalBinding('config').hasIntl) {
72
73
for ( var i = 0 ; i < str . length ; i ++ ) {
73
74
const code = str . codePointAt ( i ) ;
74
75
75
- if ( code >= 0x10000 ) { // surrogates
76
+ if ( code >= kUTF16SurrogateThreshold ) { // Surrogates.
76
77
i ++ ;
77
78
}
78
79
@@ -580,6 +581,7 @@ module.exports = {
580
581
getStringWidth,
581
582
isFullWidthCodePoint,
582
583
kEscapeCodeTimeout,
584
+ kUTF16SurrogateThreshold,
583
585
moveCursor,
584
586
stripVTControlCharacters,
585
587
CSI // CSI is only exported for testing purposes.
You can’t perform that action at this time.
0 commit comments