File tree 2 files changed +27
-19
lines changed
2 files changed +27
-19
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,29 @@ CSI.kClearToLineEnd = CSI`0K`;
36
36
CSI . kClearLine = CSI `2K` ;
37
37
CSI . kClearScreenDown = CSI `0J` ;
38
38
39
+ // TODO(BridgeAR): Treat combined characters as single character, i.e,
40
+ // 'a\u0301' and '\u0301a' (both have the same visual output).
41
+ // Check Canonical_Combining_Class in
42
+ // http://userguide.icu-project.org/strings/properties
43
+ function charLengthLeft ( str , i ) {
44
+ if ( i <= 0 )
45
+ return 0 ;
46
+ if ( ( i > 1 && str . codePointAt ( i - 2 ) >= kUTF16SurrogateThreshold ) ||
47
+ str . codePointAt ( i - 1 ) >= kUTF16SurrogateThreshold ) {
48
+ return 2 ;
49
+ }
50
+ return 1 ;
51
+ }
52
+
53
+ function charLengthAt ( str , i ) {
54
+ if ( str . length <= i ) {
55
+ // Pretend to move to the right. This is necessary to autocomplete while
56
+ // moving to the right.
57
+ return 1 ;
58
+ }
59
+ return str . codePointAt ( i ) >= kUTF16SurrogateThreshold ? 2 : 1 ;
60
+ }
61
+
39
62
if ( internalBinding ( 'config' ) . hasIntl ) {
40
63
const icu = internalBinding ( 'icu' ) ;
41
64
// icu.getStringWidth(string, ambiguousAsFullWidth, expandEmojiSequence)
@@ -452,6 +475,8 @@ function commonPrefix(strings) {
452
475
}
453
476
454
477
module . exports = {
478
+ charLengthAt,
479
+ charLengthLeft,
455
480
commonPrefix,
456
481
emitKeys,
457
482
getStringWidth,
Original file line number Diff line number Diff line change @@ -49,6 +49,8 @@ const { validateString } = require('internal/validators');
49
49
const { inspect } = require ( 'internal/util/inspect' ) ;
50
50
const EventEmitter = require ( 'events' ) ;
51
51
const {
52
+ charLengthAt,
53
+ charLengthLeft,
52
54
commonPrefix,
53
55
CSI ,
54
56
emitKeys,
@@ -591,25 +593,6 @@ Interface.prototype._wordRight = function() {
591
593
}
592
594
} ;
593
595
594
- function charLengthLeft ( str , i ) {
595
- if ( i <= 0 )
596
- return 0 ;
597
- if ( ( i > 1 && str . codePointAt ( i - 2 ) >= kUTF16SurrogateThreshold ) ||
598
- str . codePointAt ( i - 1 ) >= kUTF16SurrogateThreshold ) {
599
- return 2 ;
600
- }
601
- return 1 ;
602
- }
603
-
604
- function charLengthAt ( str , i ) {
605
- if ( str . length <= i ) {
606
- // Pretend to move to the right. This is necessary to autocomplete while
607
- // moving to the right.
608
- return 1 ;
609
- }
610
- return str . codePointAt ( i ) >= kUTF16SurrogateThreshold ? 2 : 1 ;
611
- }
612
-
613
596
Interface . prototype . _deleteLeft = function ( ) {
614
597
if ( this . cursor > 0 && this . line . length > 0 ) {
615
598
// The number of UTF-16 units comprising the character to the left
You can’t perform that action at this time.
0 commit comments