File tree 2 files changed +35
-3
lines changed
2 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -670,13 +670,14 @@ Interface.prototype._getDisplayPos = function(str) {
670
670
row += 1 ;
671
671
continue ;
672
672
}
673
- if ( isFullWidthCodePoint ( code ) ) {
673
+ const width = getStringWidth ( code ) ;
674
+ if ( width === 0 || width === 1 ) {
675
+ offset += width ;
676
+ } else { // width === 2
674
677
if ( ( offset + 1 ) % col === 0 ) {
675
678
offset ++ ;
676
679
}
677
680
offset += 2 ;
678
- } else {
679
- offset ++ ;
680
681
}
681
682
}
682
683
var cols = offset % col ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+ require ( '../common' ) ;
3
+ const { PassThrough } = require ( 'stream' ) ;
4
+ const readline = require ( 'readline' ) ;
5
+ const assert = require ( 'assert' ) ;
6
+
7
+ const ctrlU = { ctrl : true , name : 'u' } ;
8
+
9
+ {
10
+ const input = new PassThrough ( ) ;
11
+ const rl = readline . createInterface ( {
12
+ terminal : true ,
13
+ input : input ,
14
+ prompt : ''
15
+ } ) ;
16
+
17
+ for ( const [ cursor , string ] of [
18
+ [ 1 , 'a' ] ,
19
+ [ 2 , 'ab' ] ,
20
+ [ 2 , '丁' ] ,
21
+ [ 0 , '\u0301' ] , // COMBINING ACUTE ACCENT
22
+ [ 1 , 'a\u0301' ] , // á
23
+ [ 0 , '\u20DD' ] , // COMBINING ENCLOSING CIRCLE
24
+ [ 2 , 'a\u20DDb' ] , // a⃝b
25
+ [ 0 , '\u200E' ] // LEFT-TO-RIGHT MARK
26
+ ] ) {
27
+ rl . write ( string ) ;
28
+ assert . strictEqual ( rl . _getCursorPos ( ) . cols , cursor ) ;
29
+ rl . write ( null , ctrlU ) ;
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments