summaryrefslogtreecommitdiff
path: root/js/codeq/console.js
diff options
context:
space:
mode:
authorAleš Smodiš <aless@guru.si>2015-09-01 06:40:33 +0200
committerAleš Smodiš <aless@guru.si>2015-09-01 06:40:33 +0200
commit63ed43e8a0fbe5f8d17fe67b2b262356eeb5c47c (patch)
treec33e7260d5869853465242d7d9ffea85e3499a61 /js/codeq/console.js
parentab8eb70608654ff00cc1c8d3daa0edc79ab50914 (diff)
Bugfix terminal: cursor movement on input.
Diffstat (limited to 'js/codeq/console.js')
-rw-r--r--js/codeq/console.js46
1 files changed, 40 insertions, 6 deletions
diff --git a/js/codeq/console.js b/js/codeq/console.js
index 7dba8e1..bc7f3c6 100644
--- a/js/codeq/console.js
+++ b/js/codeq/console.js
@@ -414,17 +414,51 @@
this.splice(row, col, row, col, text, className || 'output');
},
- 'append': function (text, className) {
+ 'append': function (text, className, dontMoveCursor) {
// we add to the end, so optimize: do not call splice(), it is too heavy for this purpose
var newLines = formNewLines(text),
- startRow = currentRow,
+ originalCurrentRow = currentRow,
+ startRow = lines.length - 1,
i, lineDescriptor;
if (newLines.length == 0) return; // nothing to do
- lineDescriptor = lines[currentRow];
+ lineDescriptor = lines[startRow];
lineDescriptor.content = lineDescriptor.content + newLines[0];
- renderLine(lineDescriptor);
for (i = 1; i < newLines.length; i++) {
- renderLine(this.insertRow(startRow + i, newLines[i], className, true));
+ lineDescriptor = this.insertRow(startRow + i, newLines[i], className, true);
+ }
+ if (!dontMoveCursor) {
+ currentRow = lines.length - 1;
+ currentCol = lines[currentRow].content.length;
+ }
+ this.reflow(startRow < originalCurrentRow ? startRow : originalCurrentRow);
+ },
+
+ 'insertAtCursor': function (text, className, dontMoveCursor) {
+ var startRow = currentRow,
+ currentLine = lines[currentRow],
+ currentContent = currentLine.content,
+ part1 = currentContent.substring(0, currentCol),
+ part2 = currentContent.substring(currentCol),
+ newLines = formNewLines(text),
+ i, n;
+ if (newLines.length == 0) return; // nothing to do
+ else if (newLines.length == 1) {
+ currentLine.content = part1 + newLines[0] + part2;
+ if (!dontMoveCursor) currentCol += newLines[0].length;
+ renderLine(currentLine);
+ }
+ else {
+ currentLine.content = part1 + newLines[0];
+ n = newLines.length - 1;
+ for (i = 1; i < n; i++) {
+ this.insertRow(startRow + i, newLines[i], className, true);
+ }
+ this.insertRow(startRow + n, newLines[n] + part2, className, true);
+ if (!dontMoveCursor) {
+ currentRow = startRow + n;
+ currentCol = newLines[n].length;
+ }
+ this.reflow(startRow);
}
},
@@ -537,7 +571,7 @@
}
// now serve the cooking
- handler.append(cookedChars, 'input'); // append what we have to the display
+ handler.insertAtCursor(cookedChars, 'input'); // append what we have to the display
if (typeof handler.onInput === 'function') { // now tell the owner what we've done
if (lineBuffered) {
if (currentRow !== startingRow) {