@@ -490,9 +490,6 @@ Interface.prototype._insertString = function(c) {
490490} else {
491491this . _writeToOutput ( c ) ;
492492}
493-
494- // A hack to get the line refreshed if it's needed
495- this . _moveCursor ( 0 ) ;
496493}
497494} ;
498495
@@ -731,6 +728,12 @@ Interface.prototype._getDisplayPos = function(str) {
731728offset = 0 ;
732729continue ;
733730}
731+ // Tabs must be aligned by an offset of 8.
732+ // TODO(BridgeAR): Make the tab size configurable.
733+ if ( char === '\t' ) {
734+ offset += 8 - ( offset % 8 ) ;
735+ continue ;
736+ }
734737const width = getStringWidth ( char ) ;
735738if ( width === 0 || width === 1 ) {
736739offset += width ;
@@ -768,33 +771,27 @@ Interface.prototype._getCursorPos = Interface.prototype.getCursorPos;
768771
769772
770773// This function moves cursor dx places to the right
771- // (-dx for left) and refreshes the line if it is needed
774+ // (-dx for left) and refreshes the line if it is needed.
772775Interface . prototype . _moveCursor = function ( dx ) {
773- const oldcursor = this . cursor ;
776+ if ( dx === 0 ) {
777+ return ;
778+ }
774779const oldPos = this . getCursorPos ( ) ;
775780this . cursor += dx ;
776781
777- // bounds check
778- if ( this . cursor < 0 ) this . cursor = 0 ;
779- else if ( this . cursor > this . line . length ) this . cursor = this . line . length ;
782+ // Bounds check
783+ if ( this . cursor < 0 ) {
784+ this . cursor = 0 ;
785+ } else if ( this . cursor > this . line . length ) {
786+ this . cursor = this . line . length ;
787+ }
780788
781789const newPos = this . getCursorPos ( ) ;
782790
783- // Check if cursors are in the same line
791+ // Check if cursor stayed on the line.
784792if ( oldPos . rows === newPos . rows ) {
785- const diffCursor = this . cursor - oldcursor ;
786- let diffWidth ;
787- if ( diffCursor < 0 ) {
788- diffWidth = - getStringWidth (
789- this . line . substring ( this . cursor , oldcursor )
790- ) ;
791- } else if ( diffCursor > 0 ) {
792- diffWidth = getStringWidth (
793- this . line . substring ( this . cursor , oldcursor )
794- ) ;
795- }
793+ const diffWidth = newPos . cols - oldPos . cols ;
796794moveCursor ( this . output , diffWidth , 0 ) ;
797- this . prevRows = newPos . rows ;
798795} else {
799796this . _refreshLine ( ) ;
800797}
0 commit comments