From 524db02228f4bf9eababb7f2932f2ed898147bc7 Mon Sep 17 00:00:00 2001 From: runarberg Date: Thu, 9 Jun 2016 13:05:50 +0000 Subject: [PATCH 1/3] Fix Ctrl/Shift + insert copy/paste Many systems (including MS Windows and many linuxes) map `` + `` to copy and ` + ` to paste. That serves as a handy fallback when the more common ` + C` and ` + V` keybindings have their default prevented to send signals to the terminal. Currently all keydown-events with the insert key send `\x1b[2~` to the terminal. This commit won't send that key if either the `shiftKey` or the `ctrlKey` are present. Instead it will enable `contentEditable` to allow for pasting. --- src/xterm.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/xterm.js b/src/xterm.js index b17437cc..3a8da861 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -519,6 +519,11 @@ term.leaseContentEditable(); } } + + if (!term.isMac && ev.keyCode == 45 && ev.shiftKey && !ev.ctrlKey) { + // Shift + Insert pastes on windows and many linuxes + term.leaseContentEditable(); + } }); /** @@ -2387,7 +2392,11 @@ break; // insert case 45: - key = '\x1b[2~'; + if (!ev.shiftKey && !ev.ctrlKey) { + // or + are used to + // copy-paste on some systems. + key = '\x1b[2~'; + } break; // home case 36: From da9f86f1a7764b50a03ee8fcd77d12a660c8b5b0 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Thu, 9 Jun 2016 19:59:59 -0700 Subject: [PATCH 2/3] Draw cursor at correct position when scrolling Fixes #64 --- src/xterm.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/xterm.js b/src/xterm.js index b17437cc..f75989ee 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -1102,9 +1102,8 @@ line = this.lines[row]; out = ''; - if (y === this.y + if (this.y === y - (this.ybase - this.ydisp) && this.cursorState - && (this.ydisp === this.ybase) && !this.cursorHidden) { x = this.x; } else { From eee99f62e15f9449321b82bb890d47fc472d9743 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Thu, 9 Jun 2016 21:05:45 -0700 Subject: [PATCH 3/3] Improve scroll to work with blank lines after the cursor This commit works fixes scrolling when there were blank lines after the cursor. Here is what it does (blank rows are those added by running `clear`): when increasing rows: if there are blank rows below the cursor: add a blank row to the bottom else if there is room in the buffer above the viewport scroll up else add a blank row to the bottom when decreasing rows: if there are blank rows below the cursor: remove a blank row from the bottom else scroll down Fixes #111 --- src/xterm.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/xterm.js b/src/xterm.js index b17437cc..f07dcc75 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -2607,7 +2607,8 @@ , el , i , j - , ch; + , ch + , addToY; if (x === this.cols && y === this.rows) { return; @@ -2639,11 +2640,23 @@ // resize rows j = this.rows; + addToY = 0; if (j < y) { el = this.element; while (j++ < y) { + // y is rows, not this.y if (this.lines.length < y + this.ybase) { - this.lines.push(this.blankLine()); + if (this.ybase > 0 && this.lines.length <= this.ybase + this.y + addToY + 1) { + // There is room above the buffer and there are no empty elements below the line, + // scroll up + this.ybase--; + this.ydisp--; + addToY++ + } else { + // Add a blank line if there is no buffer left at the top to scroll to, or if there + // are blank lines after the cursor + this.lines.push(this.blankLine()); + } } if (this.children.length < y) { this.insertRow(); @@ -2652,11 +2665,11 @@ } else { // (j > y) while (j-- > y) { if (this.lines.length > y + this.ybase) { - if (this.y + this.ybase < j) { - // The line is after the cursor, remove it + if (this.lines.length > this.ybase + this.y + 1) { + // The line is a blank line below the cursor, remove it this.lines.pop(); } else { - // The line is the cursor, push the viewport down + // The line is the cursor, scroll down this.ybase++; this.ydisp++; } @@ -2676,6 +2689,9 @@ if (this.y >= y) { this.y = y - 1; } + if (addToY) { + this.y += addToY; + } if (this.x >= x) { this.x = x - 1;