From d9ea2958593256939e1c1dfb52fefd037dad0ff3 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Tue, 26 May 2015 22:57:34 -0600 Subject: [PATCH] * More experimental cursor positioning --- core/multi_line_edit_text_view.js | 39 ++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/core/multi_line_edit_text_view.js b/core/multi_line_edit_text_view.js index 53acc380..b8e8c96e 100644 --- a/core/multi_line_edit_text_view.js +++ b/core/multi_line_edit_text_view.js @@ -236,20 +236,44 @@ function MultiLineEditTextView(options) { }; + this.getCharAtCursorPosition = function() { + var pos = self.getTextBufferPosition(self.cursorPos.row, self.cursorPos.col); + return self.textBuffer.get(pos); + }; + this.cursorUp = function() { if(self.cursorPos.row > 0) { self.cursorPos.row--; - console.log(self.textBuffer.asArray().join('').slice(self.getTextBufferPosition(self.cursorPos.row, 0), 1)); + } else if(self.topLineIndex > 0) { // :TODO: scroll } - - // :TODO: if there is text @ cursor y position we're ok, otherwise, // jump to the end of the line }; + this.cursorRight = function() { + var max = Math.min(self.dimens.width, self.renderBuffer[self.cursorPos.row].length); + if(self.cursorPos.col < max) { + self.cursorPos.col++; + } else { + + } + }; + + this.cursorLeft = function() { + if(self.cursorPos.col > 0) { + self.cursorPos.col--; + } else { + if(self.cursorPos.row > 0) { + self.cursorPos.row--; + self.cursorPos.col = self.renderBuffer[self.cursorPos.row].length; + } + //self.cursorUp(); + } + }; + this.getLineIndex = function() { return self.topLineIndex + self.cursorPos.row; }; @@ -298,7 +322,8 @@ MultiLineEditTextView.prototype.setText = function(text) { for(var i = idx; i < idx + 4; ++i) { console.log(i + ' = "' + this.textBuffer.asArray()[i] + '"'); } - this.cursorPos.row = 3; + this.cursorPos.row = 15; + this.cursorPos.col = 0; } MultiLineEditTextView.prototype.onSpecialKeyPress = function(keyName) { @@ -307,10 +332,12 @@ MultiLineEditTextView.prototype.onSpecialKeyPress = function(keyName) { } else if(this.isSpecialKeyMapped('down', keyName)) { } else if(this.isSpecialKeyMapped('left', keyName)) { - + this.cursorLeft(); } else if(this.isSpecialKeyMapped('right', keyName)) { - + this.cursorRight(); } + console.log(this.getCharAtCursorPosition()); + MultiLineEditTextView.super_.prototype.onSpecialKeyPress.call(this, keyName); } \ No newline at end of file