Fix some word wrap bugs previously introduced

This commit is contained in:
Bryan Ashby 2018-02-04 21:01:19 -07:00
parent aecc24079f
commit 7555233ac7

View file

@ -411,6 +411,9 @@ function MultiLineEditTextView(options) {
}; };
this.insertCharactersInText = function(c, index, col) { this.insertCharactersInText = function(c, index, col) {
const prevTextLength = self.getTextLength(index);
let editingEol = self.cursorPos.col === prevTextLength;
self.textLines[index].text = [ self.textLines[index].text = [
self.textLines[index].text.slice(0, col), self.textLines[index].text.slice(0, col),
c, c,
@ -419,18 +422,17 @@ function MultiLineEditTextView(options) {
self.cursorPos.col += c.length; self.cursorPos.col += c.length;
let cursorOffset;
let absPos;
if(self.getTextLength(index) > self.dimens.width) { if(self.getTextLength(index) > self.dimens.width) {
// //
// Update word wrapping and |cursorOffset| if the cursor // Update word wrapping and |cursorOffset| if the cursor
// was within the bounds of the wrapped text // was within the bounds of the wrapped text
// //
let cursorOffset;
const lastCol = self.cursorPos.col - c.length; const lastCol = self.cursorPos.col - c.length;
const firstWrapRange = self.updateTextWordWrap(index); const firstWrapRange = self.updateTextWordWrap(index);
if(lastCol >= firstWrapRange.start && lastCol <= firstWrapRange.end) { if(lastCol >= firstWrapRange.start && lastCol <= firstWrapRange.end) {
cursorOffset = self.cursorPos.col - firstWrapRange.start; cursorOffset = self.cursorPos.col - firstWrapRange.start;
editingEol = true; //override
} else { } else {
cursorOffset = firstWrapRange.end; cursorOffset = firstWrapRange.end;
} }
@ -438,14 +440,22 @@ function MultiLineEditTextView(options) {
// redraw from current row to end of visible area // redraw from current row to end of visible area
self.redrawRows(self.cursorPos.row, self.dimens.height); self.redrawRows(self.cursorPos.row, self.dimens.height);
self.cursorBeginOfNextLine(); // If we're editing mid, we're done here. Else, we need to
self.cursorPos.col += cursorOffset; // move the cursor to the new editing position after a wrap
self.client.term.rawWrite(ansi.right(cursorOffset)); if(editingEol) {
self.cursorBeginOfNextLine();
self.cursorPos.col += cursorOffset;
self.client.term.rawWrite(ansi.right(cursorOffset));
} else {
// adjust cursor after drawing new rows
const absPos = self.getAbsolutePosition(self.cursorPos.row, self.cursorPos.col);
self.client.term.rawWrite(ansi.goto(absPos.row, absPos.col));
}
} else { } else {
// //
// We must only redraw from col -> end of current visible line // We must only redraw from col -> end of current visible line
// //
absPos = self.getAbsolutePosition(self.cursorPos.row, self.cursorPos.col); const absPos = self.getAbsolutePosition(self.cursorPos.row, self.cursorPos.col);
const renderText = self.getRenderText(index).slice(self.cursorPos.col - c.length); const renderText = self.getRenderText(index).slice(self.cursorPos.col - c.length);
self.client.term.write( self.client.term.write(