* Fix crash when deleting last line in MultiLineTextEdit

This commit is contained in:
Bryan Ashby 2015-07-06 22:52:07 -06:00
parent 40e0b55424
commit ab39fcd1ba
1 changed files with 13 additions and 3 deletions

View File

@ -356,7 +356,9 @@ function MultiLineEditTextView(options) {
// treat all of these things using the physical approach, but this seems // treat all of these things using the physical approach, but this seems
// a bit odd in this context. // a bit odd in this context.
// //
var hadEol = self.textLines[index].eol; var isLastLine = (index === self.textLines.length - 1);
var hadEol = self.textLines[index].eol;
self.textLines.splice(index, 1); self.textLines.splice(index, 1);
if(hadEol && self.textLines.length > index && !self.textLines[index].eol) { if(hadEol && self.textLines.length > index && !self.textLines[index].eol) {
self.textLines[index].eol = true; self.textLines[index].eol = true;
@ -367,14 +369,22 @@ function MultiLineEditTextView(options) {
// :TODO: Make this a method // :TODO: Make this a method
if(self.textLines.length < 1) { if(self.textLines.length < 1) {
self.textLines = [ { text : '', eol : true } ]; self.textLines = [ { text : '', eol : true } ];
isLastLine = false; // resetting
} }
self.cursorPos.col = 0; self.cursorPos.col = 0;
var lastRow = self.redrawRows(self.cursorPos.row, self.dimens.height); var lastRow = self.redrawRows(self.cursorPos.row, self.dimens.height);
self.eraseRows(lastRow, self.dimens.height); self.eraseRows(lastRow, self.dimens.height);
self.moveClientCusorToCursorPos(); //
// If we just deleted the last line in the buffer, move up
//
if(isLastLine) {
self.cursorEndOfPreviousLine();
} else {
self.moveClientCusorToCursorPos();
}
} }
}; };