From 5a6b283923170e6057d6850d3cd627e7cb82cb1a Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Wed, 27 May 2015 22:53:21 -0600 Subject: [PATCH] * Fix backspace in edit views * Some notes --- core/edit_text_view.js | 2 +- core/multi_line_edit_text_view.js | 51 +++++-------------------------- 2 files changed, 8 insertions(+), 45 deletions(-) diff --git a/core/edit_text_view.js b/core/edit_text_view.js index e480888f..34ad6caa 100644 --- a/core/edit_text_view.js +++ b/core/edit_text_view.js @@ -20,7 +20,7 @@ function EditTextView(options) { TextView.call(this, options); - this.cursorPos = { x : 0 }; + this.cursorPos = { row : 0, col : 0 }; this.clientBackspace = function() { var fillCharSGR = this.getStyleSGR(1) || this.getSGR(); diff --git a/core/multi_line_edit_text_view.js b/core/multi_line_edit_text_view.js index c4e8465a..f9f0348a 100644 --- a/core/multi_line_edit_text_view.js +++ b/core/multi_line_edit_text_view.js @@ -73,6 +73,8 @@ exports.MultiLineEditTextView = MultiLineEditTextView; // https://github.com/chjj/blessed // +// need self.skipTabs(dir): if pos='\t', skip ahead (in dir) until reg char. This can be used @ up, left, right, down + function MultiLineEditTextView(options) { if(!_.isBoolean(options.acceptsFocus)) { @@ -104,50 +106,6 @@ function MultiLineEditTextView(options) { this.cursorPos = { row : 0, col : 0 }; // relative to view window this.renderStartIndex = 0; - /* - this.redrawViewableText = function() { - // - // v--- position.row/y - // +-----------------------------------+ <--- x + width - // | | - // | | - // | | - // +-----------------------------------+ - // ^--- position.row + height - // - // A given line in lines[] may need to take up 1:n physical lines - // due to wrapping / available space. - // - var x = self.position.row; - var bottom = x + self.dimens.height; - var idx = self.topLineIndex; - - self.client.term.write(self.getSGR()); - - var lines; - while(idx < self.lines.length && x < bottom) { - if(0 === self.lines[idx].length) { - ++x; - } else { - lines = self.wordWrap(self.lines[idx]); - for(var y = 0; y < lines.length && x < bottom; ++y) { - self.client.term.write(ansi.goto(x, this.position.col)); - self.client.term.write(lines[y]); - ++x; - } - } - - ++idx; - } - }; - */ - - /* - this.createScrollRegion = function() { - self.client.term.write(ansi.setScrollRegion(self.position.row, self.position.row + 5));//self.dimens.height)); - }; - */ - this.getTabString = function() { return new Array(self.tabWidth).join(' '); }; @@ -236,6 +194,10 @@ function MultiLineEditTextView(options) { //return self.renderBuffer[row].replace(/\n/g, '').length; }; + this.getLineTextLengthToColumn = function(row, col) { + return self.renderBuffer[row].replace(self.getReplaceTabsRegExp(), '\t').replace(/\n/g, '').slice(0, col).length; + }; + this.getEndOfLinePosition = function(row) { row = row || self.cursorPos.row; return self.position.col + self.getLineTextLength(row); @@ -267,6 +229,7 @@ function MultiLineEditTextView(options) { this.cursorUp = function() { if(self.cursorPos.row > 0) { + self.cursorPos.col = self.getLineTextLengthToColumn(self.cursorPos.row, self.cursorPos.col); self.cursorPos.row--; self.client.term.write(ansi.up()); } else if(self.topLineIndex > 0) {