* Separate out DEL vs backspace when possible for ANSI-BBS terminals. *nix terminals don't send us what we need, but deal with it.

* Handle delete in MultiLineTextEditView. More to come soon!
This commit is contained in:
Bryan Ashby 2017-09-24 11:15:38 -06:00
parent 47551b1803
commit e37409e9b5
2 changed files with 39 additions and 18 deletions

View file

@ -67,7 +67,7 @@ const SPECIAL_KEY_MAP_DEFAULT = {
'line feed' : [ 'return' ],
exit : [ 'esc' ],
backspace : [ 'backspace' ],
delete : [ 'del' ],
delete : [ 'delete' ],
tab : [ 'tab' ],
up : [ 'up arrow' ],
down : [ 'down arrow' ],
@ -354,21 +354,14 @@ function MultiLineEditTextView(options) {
};
this.removeCharactersFromText = function(index, col, operation, count) {
if('right' === operation) {
if('delete' === operation) {
self.textLines[index].text =
self.textLines[index].text.slice(col, count) +
self.textLines[index].text.slice(0, col) +
self.textLines[index].text.slice(col + count);
self.cursorPos.col -= count;
self.updateTextWordWrap(index);
self.redrawRows(self.cursorPos.row, self.dimens.height);
if(0 === self.textLines[index].text) {
} else {
self.redrawRows(self.cursorPos.row, self.dimens.height);
}
self.moveClientCursorToCursorPos();
} else if ('backspace' === operation) {
// :TODO: method for splicing text
self.textLines[index].text =
@ -868,11 +861,25 @@ function MultiLineEditTextView(options) {
};
this.keyPressDelete = function() {
self.removeCharactersFromText(
self.getTextLinesIndex(),
self.cursorPos.col,
'right',
1);
const lineIndex = self.getTextLinesIndex();
if(0 === self.cursorPos.col && 0 === self.textLines[lineIndex].text.length && self.textLines.length > 0) {
//
// Start of line and nothing left. Just delete the line
//
self.removeCharactersFromText(
lineIndex,
0,
'delete line'
);
} else {
self.removeCharactersFromText(
lineIndex,
self.cursorPos.col,
'delete',
1
);
}
self.emitEditPosition();
};
@ -1143,7 +1150,7 @@ const HANDLED_SPECIAL_KEYS = [
'line feed',
'insert',
'tab',
'backspace', 'del',
'backspace', 'delete',
'delete line',
];