Support copying of select all text

This commit is contained in:
Daniel Imms
2017-05-25 11:35:22 -07:00
parent 25152e4441
commit 43c796a781
2 changed files with 20 additions and 5 deletions
+15 -5
View File
@@ -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]));
}
+5
View File
@@ -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;
}