Add hasSelection public API

This commit is contained in:
Daniel Imms 2017-06-07 12:40:48 -07:00
parent 9e47ec9af2
commit 1343b83fc3
2 changed files with 15 additions and 1 deletions

View File

@ -145,6 +145,13 @@ export class SelectionManager extends EventEmitter {
this._buffer = buffer;
}
/**
* Gets whether there is an active text selection.
*/
public get hasSelection(): boolean {
return !!this._model.finalSelectionStart && !!this._model.finalSelectionEnd;
}
/**
* Gets the text currently selected.
*/

View File

@ -1373,11 +1373,18 @@ Terminal.prototype.deregisterLinkMatcher = function(matcherId) {
}
}
/**
* Gets whether the terminal has an active selection.
*/
Terminal.prototype.hasSelection = function() {
return this.selectionManager.hasSelection;
}
/**
* Gets the terminal's current selection, this is useful for implementing copy
* behavior outside of xterm.js.
*/
Terminal.prototype.getSelectionText = function() {
Terminal.prototype.getSelection = function() {
// TODO: Should prepareTextForClipboard logic be moved to SelectionManager?
return prepareTextForClipboard(this.selectionManager.selectionText);
}