mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-07-23 19:20:41 +02:00
* Fix some visible vs non-visible, WIP stuff
This commit is contained in:
parent
30b6cbedfb
commit
9be258dab5
1 changed files with 66 additions and 12 deletions
|
@ -61,7 +61,10 @@ function MultiLineEditTextView2(options) {
|
||||||
this.cursorPos = { col : 0, row : 0 };
|
this.cursorPos = { col : 0, row : 0 };
|
||||||
|
|
||||||
this.getTextLinesIndex = function(row) {
|
this.getTextLinesIndex = function(row) {
|
||||||
var index = self.topVisibleIndex + self.cursorPos.row;
|
if(!_.isNumber(row)) {
|
||||||
|
row = self.cursorPos.row;
|
||||||
|
}
|
||||||
|
var index = self.topVisibleIndex + row;
|
||||||
return index;
|
return index;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -75,7 +78,6 @@ function MultiLineEditTextView2(options) {
|
||||||
var row = self.position.row;
|
var row = self.position.row;
|
||||||
for(var i = self.topVisibleIndex; i < bottomIndex; i++) {
|
for(var i = self.topVisibleIndex; i < bottomIndex; i++) {
|
||||||
self.client.term.write(ansi.goto(row, this.position.col));
|
self.client.term.write(ansi.goto(row, this.position.col));
|
||||||
//self.client.term.write(self.getRenderText(self.textLines[i].text));
|
|
||||||
self.client.term.write(self.getRenderText(i));
|
self.client.term.write(self.getRenderText(i));
|
||||||
++row;
|
++row;
|
||||||
}
|
}
|
||||||
|
@ -83,10 +85,23 @@ function MultiLineEditTextView2(options) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getVisibleText = function(index) {
|
this.getVisibleText = function(index) {
|
||||||
index = _.isNumber(index) ? index : self.getTextLinesIndex(self.cursorPos.row);
|
if(!_.isNumber(index)) {
|
||||||
|
index = self.getTextLinesIndex();
|
||||||
|
}
|
||||||
return self.textLines[index].text.replace(/\t/g, ' ');
|
return self.textLines[index].text.replace(/\t/g, ' ');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.getText = function(index) {
|
||||||
|
if(!_.isNumber(index)) {
|
||||||
|
index = self.getTextLinesIndex();
|
||||||
|
}
|
||||||
|
return self.textLines[index].text;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.getTextEndOfLineColumn = function(index) {
|
||||||
|
return Math.max(0, self.getText(index).length - 1);
|
||||||
|
};
|
||||||
|
|
||||||
this.getRenderText = function(index) {
|
this.getRenderText = function(index) {
|
||||||
var text = self.getVisibleText(index);
|
var text = self.getVisibleText(index);
|
||||||
var remain = self.dimens.width - text.length;
|
var remain = self.dimens.width - text.length;
|
||||||
|
@ -229,9 +244,22 @@ function MultiLineEditTextView2(options) {
|
||||||
} else if(self.topVisibleIndex > 0) {
|
} else if(self.topVisibleIndex > 0) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.adjustCursorIfPastEndOfLine();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.cursorDown = function() {
|
this.cursorDown = function() {
|
||||||
|
var lastVisibleRow = Math.min(self.dimens.height, self.textLines.length) - 1;
|
||||||
|
if(self.cursorPos.row < lastVisibleRow) {
|
||||||
|
self.cursorPos.row++;
|
||||||
|
self.client.term.write(ansi.down());
|
||||||
|
|
||||||
|
// :TODO: make tab adjustment if needed
|
||||||
|
} else {
|
||||||
|
// :TODO: can we scroll down more?
|
||||||
|
}
|
||||||
|
|
||||||
|
self.adjustCursorIfPastEndOfLine();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.cursorLeft = function() {
|
this.cursorLeft = function() {
|
||||||
|
@ -245,8 +273,8 @@ function MultiLineEditTextView2(options) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.cursorRight = function() {
|
this.cursorRight = function() {
|
||||||
var colEnd = self.getVisibleText(self.cursorPos.row).length;
|
var eolColumn = self.getTextEndOfLineColumn();
|
||||||
if(self.cursorPos.col < colEnd) {
|
if(self.cursorPos.col < eolColumn) {
|
||||||
self.cursorPos.col++;
|
self.cursorPos.col++;
|
||||||
self.client.term.write(ansi.right());
|
self.client.term.write(ansi.right());
|
||||||
|
|
||||||
|
@ -269,11 +297,19 @@ function MultiLineEditTextView2(options) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.cursorEnd = function() {
|
this.cursorEnd = function() {
|
||||||
self.cursorPos.col = Math.max(self.getVisibleText().length - 1, 0);
|
self.cursorPos.col = self.getTextEndOfLineColumn();
|
||||||
self.moveClientCusorToCursorPos();
|
self.moveClientCusorToCursorPos();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.cursorStartOfText = function() {
|
this.adjustCursorIfPastEndOfLine = function() {
|
||||||
|
var eolColumn = self.getTextEndOfLineColumn();
|
||||||
|
if(self.cursorPos.col > eolColumn) {
|
||||||
|
self.cursorPos.col = eolColumn;
|
||||||
|
self.moveClientCusorToCursorPos();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.cursorStartOfDocument = function() {
|
||||||
self.topVisibleIndex = 0;
|
self.topVisibleIndex = 0;
|
||||||
self.cursorPos = { row : 0, col : 0 };
|
self.cursorPos = { row : 0, col : 0 };
|
||||||
|
|
||||||
|
@ -281,15 +317,32 @@ function MultiLineEditTextView2(options) {
|
||||||
self.moveClientCusorToCursorPos();
|
self.moveClientCusorToCursorPos();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.cursorEndOfText = function() {
|
this.cursorEndOfDocument = function() {
|
||||||
self.topVisibleIndex = Math.max(self.textLines.length - self.dimens.height, 0);
|
self.topVisibleIndex = Math.max(self.textLines.length - self.dimens.height, 0);
|
||||||
self.cursorPos.row = (self.textLines.length - self.topVisibleIndex) - 1;
|
self.cursorPos.row = (self.textLines.length - self.topVisibleIndex) - 1;
|
||||||
self.cursorPos.col = self.getVisibleText().length; // uses row set above
|
self.cursorPos.col = self.getTextEndOfLineColumn();
|
||||||
|
|
||||||
self.redraw();
|
self.redraw();
|
||||||
self.moveClientCusorToCursorPos();
|
self.moveClientCusorToCursorPos();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.scrollDocumentUp = function() {
|
||||||
|
//
|
||||||
|
// Note: We scroll *up* when the cursor goes *down* beyond
|
||||||
|
// the visible area!
|
||||||
|
//
|
||||||
|
var linesBelow = self.textLines.length - (self.topVisibleIndex + self.cursorPos.row);
|
||||||
|
if(linesBelow > 0) {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.scrollDocumentDown = function() {
|
||||||
|
//
|
||||||
|
// Note: We scroll *down* when the cursor goes *up* beyond
|
||||||
|
// the visible area!
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
require('util').inherits(MultiLineEditTextView2, View);
|
require('util').inherits(MultiLineEditTextView2, View);
|
||||||
|
@ -306,7 +359,8 @@ MultiLineEditTextView2.prototype.setText = function(text) {
|
||||||
//text = "You. Now \ttomorrow \tthere'll \tbe \ttwo \tsessions, \tof\t course, morning and afternoon.";
|
//text = "You. Now \ttomorrow \tthere'll \tbe \ttwo \tsessions, \tof\t course, morning and afternoon.";
|
||||||
this.insertText(text);//, 0, 0);
|
this.insertText(text);//, 0, 0);
|
||||||
|
|
||||||
console.log(this.textLines)
|
//console.log(this.textLines)
|
||||||
|
this.cursorEndOfDocument();
|
||||||
};
|
};
|
||||||
|
|
||||||
MultiLineEditTextView2.prototype.onSpecialKeyPress = function(keyName) {
|
MultiLineEditTextView2.prototype.onSpecialKeyPress = function(keyName) {
|
||||||
|
@ -341,8 +395,8 @@ MultiLineEditTextView2.prototype.onSpecialKeyPress = function(keyName) {
|
||||||
|
|
||||||
// TEMP HACK FOR TESTING -----
|
// TEMP HACK FOR TESTING -----
|
||||||
if(self.isSpecialKeyMapped('lineFeed', keyName)) {
|
if(self.isSpecialKeyMapped('lineFeed', keyName)) {
|
||||||
//self.cursorStartOfText();
|
//self.cursorStartOfDocument();
|
||||||
self.cursorEndOfText();
|
self.cursorStartOfDocument();
|
||||||
}
|
}
|
||||||
|
|
||||||
//MultiLineEditTextView2.super_.prototype.onSpecialKeyPress.call(this, keyName);
|
//MultiLineEditTextView2.super_.prototype.onSpecialKeyPress.call(this, keyName);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue