* More work on cursor movement inc left key with tabs

This commit is contained in:
Bryan Ashby 2015-06-11 23:09:13 -06:00
parent b24cbd9436
commit 1b50993768
1 changed files with 57 additions and 11 deletions

View File

@ -167,6 +167,13 @@ function MultiLineEditTextView2(options) {
return self.textLines[index].text; return self.textLines[index].text;
}; };
this.getCharacter = function(index, col) {
if(!_.isNumber(col)) {
col = self.cursorPos.col;
}
return self.getText(index).charAt(col);
}
this.getTextEndOfLineColumn = function(index) { this.getTextEndOfLineColumn = function(index) {
return Math.max(0, self.getText(index).length); return Math.max(0, self.getText(index).length);
}; };
@ -480,9 +487,14 @@ function MultiLineEditTextView2(options) {
this.keyPressLeft = function() { this.keyPressLeft = function() {
if(self.cursorPos.col > 0) { if(self.cursorPos.col > 0) {
var prevChar = self.getCharacter();
self.cursorPos.col--; self.cursorPos.col--;
self.client.term.write(ansi.left()); self.client.term.write(ansi.left());
// :TODO: handle landing on a tab
if('\t' === prevChar) {
self.adjustCursorToNextTab('left');
}
} else { } else {
self.cursorEndOfPreviousLine(); self.cursorEndOfPreviousLine();
} }
@ -491,10 +503,14 @@ function MultiLineEditTextView2(options) {
this.keyPressRight = function() { this.keyPressRight = function() {
var eolColumn = self.getTextEndOfLineColumn(); var eolColumn = self.getTextEndOfLineColumn();
if(self.cursorPos.col < eolColumn) { if(self.cursorPos.col < eolColumn) {
var prevChar = self.getCharacter();
self.cursorPos.col++; self.cursorPos.col++;
self.client.term.write(ansi.right()); self.client.term.write(ansi.right());
self.adjustCursorToNextTab('right'); if('\t' === prevChar) {
self.adjustCursorToNextTab('right');
}
} else { } else {
self.cursorBeginOfNextLine(); self.cursorBeginOfNextLine();
} }
@ -554,19 +570,49 @@ function MultiLineEditTextView2(options) {
}; };
this.adjustCursorToNextTab = function(direction) { this.adjustCursorToNextTab = function(direction) {
if('\t' === self.getText()[self.cursorPos.col]) { if('\t' === self.getCharacter()) { // :TODO: should probably just be an assert
// //
// When pressing right or left, jump to the next // When pressing right or left, jump to the next
// tabstop in that direction. // tabstop in that direction.
// //
if('right' === direction) { switch(direction) {
// :TODO: This is not working correctly... case 'right' :
// A few observations: var move = self.getRemainingTabWidth();
// 1) Right/left should probably allow to land on a tab self.cursorPos.col += move;
// and only jump once another arrow is hit -- this lets the user edit @ that position self.client.term.write(ansi.right(move));
var move = self.getRemainingTabWidth(); break;
self.cursorPos.col += move;
self.client.term.write(ansi.right(move)); case 'left' :
//
// We'll move up to tabWidth spaces left
//
// return self.tabWidth - (col % self.tabWidth);
//var move = self.tabWidth - 1;
var text = self.getText();
var col = self.cursorPos.col;
var move = 0;
while(move < self.tabWidth - 2) {
if('\t' !== text.charAt(col--)) {
break;
}
move++;
}
/*
var move = self.tabWidth - 1;
for(; col > 0 && move > 0; --col, --move) {
if('\t' !== text.charAt(col)) {
break;
}
}
console.log('curCol=' + self.cursorPos.col + ' / col=' + col)
move = (self.cursorPos.col - col) - 1;
*/
console.log(move)
self.cursorPos.col -= move;
self.client.term.write(ansi.left(move));
break;
} }
} }
}; };