mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
Support copying of select all text
This commit is contained in:
+15
-5
@@ -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]));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user