@@ -490,9 +490,6 @@ Interface.prototype._insertString = function(c) { |
490 | 490 | } else { |
491 | 491 | this._writeToOutput(c); |
492 | 492 | } |
493 | | - |
494 | | - // A hack to get the line refreshed if it's needed |
495 | | - this._moveCursor(0); |
496 | 493 | } |
497 | 494 | }; |
498 | 495 |
|
@@ -731,6 +728,12 @@ Interface.prototype._getDisplayPos = function(str) { |
731 | 728 | offset = 0; |
732 | 729 | continue; |
733 | 730 | } |
| 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 | + } |
734 | 737 | const width = getStringWidth(char); |
735 | 738 | if (width === 0 || width === 1) { |
736 | 739 | offset += width; |
@@ -768,33 +771,27 @@ Interface.prototype._getCursorPos = Interface.prototype.getCursorPos; |
768 | 771 |
|
769 | 772 |
|
770 | 773 | // 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. |
772 | 775 | Interface.prototype._moveCursor = function(dx) { |
773 | | - const oldcursor = this.cursor; |
| 776 | + if (dx === 0) { |
| 777 | + return; |
| 778 | + } |
774 | 779 | const oldPos = this.getCursorPos(); |
775 | 780 | this.cursor += dx; |
776 | 781 |
|
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 | + } |
780 | 788 |
|
781 | 789 | const newPos = this.getCursorPos(); |
782 | 790 |
|
783 | | - // Check if cursors are in the same line |
| 791 | + // Check if cursor stayed on the line. |
784 | 792 | if (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; |
796 | 794 | moveCursor(this.output, diffWidth, 0); |
797 | | - this.prevRows = newPos.rows; |
798 | 795 | } else { |
799 | 796 | this._refreshLine(); |
800 | 797 | } |
|