From 43c796a781bfaceafa46fd0628ea704143f66671 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Thu, 25 May 2017 11:35:22 -0700 Subject: [PATCH] Support copying of select all text --- src/SelectionManager.ts | 20 +++++++++++++++----- src/xterm.js | 5 +++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/SelectionManager.ts b/src/SelectionManager.ts index 2ae61442b..1e6fd26e6 100644 --- a/src/SelectionManager.ts +++ b/src/SelectionManager.ts @@ -85,19 +85,29 @@ export class SelectionManager extends EventEmitter { } public get selectionText(): string { - if (!this._selectionStart || !this._selectionEnd) { + const originalStart = this.selectAllAwareSelectionStart; + const originalEnd = this.selectAllAwareSelectionEnd; + if (!originalStart || !originalEnd) { return ''; } - const flipValues = this._selectionStart[1] > this._selectionEnd[1] || - (this._selectionStart[1] === this._selectionEnd[1] && this._selectionStart[0] > this._selectionEnd[0]); - const start = flipValues ? this._selectionEnd : this._selectionStart; - const end = flipValues ? this._selectionStart : this._selectionEnd; + + // Flip values if start is after end + const flipValues = originalStart[1] > originalEnd[1] || + (originalStart[1] === originalEnd[1] && originalStart[0] > originalEnd[0]); + const start = flipValues ? originalEnd : originalStart; + const end = flipValues ? originalStart : originalEnd; + + // Get first row const startRowEndCol = start[1] === end[1] ? end[0] : null; let result: string[] = []; result.push(this._translateBufferLineToString(this._buffer.get(start[1]), start[0], startRowEndCol)); + + // Get middle rows for (let i = start[1] + 1; i <= end[1] - 1; i++) { result.push(this._translateBufferLineToString(this._buffer.get(i))); } + + // Get final row if (start[1] !== end[1]) { result.push(this._translateBufferLineToString(this._buffer.get(end[1]), 0, end[1])); } diff --git a/src/xterm.js b/src/xterm.js index 3dc786388..94979d8be 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -522,6 +522,7 @@ Terminal.prototype.initGlobal = function() { // Bind clipboard functionality on(this.element, 'copy', function (ev) { + console.log('copy event'); copyHandler.call(this, ev, term, term.selectionManager); }); on(this.textarea, 'paste', function (ev) { @@ -1701,6 +1702,10 @@ Terminal.prototype.evaluateKeyEscapeSequence = function(ev) { } else if (ev.keyCode >= 48 && ev.keyCode <= 57) { result.key = C0.ESC + (ev.keyCode - 48); } + } else if (this.browser.isMac && !ev.altKey && !ev.ctrlKey && ev.metaKey) { + if (ev.keyCode === 65) { // cmd + a + this.selectAll(); + } } break; }