@@ -735,27 +735,13 @@ Interface.prototype._getDisplayPos = function(str) {
735735 return { cols, rows } ;
736736} ;
737737
738-
739738// Returns current cursor's position and line
740739Interface . prototype . getCursorPos = function ( ) {
741- const columns = this . columns ;
742740 const strBeforeCursor = this . _prompt + this . line . substring ( 0 , this . cursor ) ;
743- const dispPos = this . _getDisplayPos ( strBeforeCursor ) ;
744- let cols = dispPos . cols ;
745- let rows = dispPos . rows ;
746- // If the cursor is on a full-width character which steps over the line,
747- // move the cursor to the beginning of the next line.
748- if ( cols + 1 === columns &&
749- this . cursor < this . line . length &&
750- getStringWidth ( this . line [ this . cursor ] ) > 1 ) {
751- rows ++ ;
752- cols = 0 ;
753- }
754- return { cols, rows } ;
741+ return this . _getDisplayPos ( strBeforeCursor ) ;
755742} ;
756743Interface . prototype . _getCursorPos = Interface . prototype . getCursorPos ;
757744
758-
759745// This function moves cursor dx places to the right
760746// (-dx for left) and refreshes the line if it is needed.
761747Interface . prototype . _moveCursor = function ( dx ) {
@@ -1119,42 +1105,39 @@ function emitKeypressEvents(stream, iface = {}) {
11191105 stream [ ESCAPE_DECODER ] = emitKeys ( stream ) ;
11201106 stream [ ESCAPE_DECODER ] . next ( ) ;
11211107
1122- const escapeCodeTimeout = ( ) => stream [ ESCAPE_DECODER ] . next ( '' ) ;
1108+ const triggerEscape = ( ) => stream [ ESCAPE_DECODER ] . next ( '' ) ;
1109+ const { escapeCodeTimeout = ESCAPE_CODE_TIMEOUT } = iface ;
11231110 let timeoutId ;
11241111
1125- function onData ( b ) {
1112+ function onData ( input ) {
11261113 if ( stream . listenerCount ( 'keypress' ) > 0 ) {
1127- const string = stream [ KEYPRESS_DECODER ] . write ( b ) ;
1114+ const string = stream [ KEYPRESS_DECODER ] . write ( input ) ;
11281115 if ( string ) {
11291116 clearTimeout ( timeoutId ) ;
11301117
11311118 // This supports characters of length 2.
11321119 iface . _sawKeyPress = charLengthAt ( string , 0 ) === string . length ;
1133- const escapeTimeout = iface . escapeCodeTimeout || ESCAPE_CODE_TIMEOUT ;
1120+ iface . isCompletionEnabled = false ;
11341121
11351122 let length = 0 ;
11361123 for ( const character of string ) {
11371124 length += character . length ;
1138- if ( character === '\t' && length ! == string . length ) {
1139- iface . isCompletionEnabled = false ;
1125+ if ( length = == string . length ) {
1126+ iface . isCompletionEnabled = true ;
11401127 }
11411128
11421129 try {
11431130 stream [ ESCAPE_DECODER ] . next ( character ) ;
11441131 // Escape letter at the tail position
1145- if ( character === kEscape && length === string . length ) {
1146- timeoutId = setTimeout ( escapeCodeTimeout , escapeTimeout ) ;
1132+ if ( length === string . length && character === kEscape ) {
1133+ timeoutId = setTimeout ( triggerEscape , escapeCodeTimeout ) ;
11471134 }
11481135 } catch ( err ) {
11491136 // If the generator throws (it could happen in the `keypress`
11501137 // event), we need to restart it.
11511138 stream [ ESCAPE_DECODER ] = emitKeys ( stream ) ;
11521139 stream [ ESCAPE_DECODER ] . next ( ) ;
11531140 throw err ;
1154- } finally {
1155- if ( iface ) {
1156- iface . isCompletionEnabled = true ;
1157- }
11581141 }
11591142 }
11601143 }
0 commit comments