]> git.proxmox.com Git - mirror_xterm.js.git/commitdiff
Add getSelectionText API
authorDaniel Imms <daimms@microsoft.com>
Wed, 7 Jun 2017 18:59:28 +0000 (11:59 -0700)
committerDaniel Imms <daimms@microsoft.com>
Wed, 7 Jun 2017 18:59:28 +0000 (11:59 -0700)
This allows consumers to implement their own copy functionality/keybindings

src/xterm.js

index 2f3a57ee279551a965b3a2921f50067d83a5e0dc..684ba45d68dbc5d6aba065d13cf253f9b64a34ff 100644 (file)
@@ -13,7 +13,7 @@
 import { CompositionHelper } from './CompositionHelper';
 import { EventEmitter } from './EventEmitter';
 import { Viewport } from './Viewport';
-import { rightClickHandler, pasteHandler, copyHandler } from './handlers/Clipboard';
+import { rightClickHandler, pasteHandler, copyHandler, prepareTextForClipboard } from './handlers/Clipboard';
 import { CircularList } from './utils/CircularList';
 import { C0 } from './EscapeSequences';
 import { InputHandler } from './InputHandler';
@@ -1373,6 +1373,15 @@ Terminal.prototype.deregisterLinkMatcher = function(matcherId) {
   }
 }
 
+/**
+ * Gets the terminal's current selection, this is useful for implementing copy
+ * behavior outside of xterm.js.
+ */
+Terminal.prototype.getSelectionText = function() {
+  // TODO: Should prepareTextForClipboard logic be moved to SelectionManager?
+  return prepareTextForClipboard(this.selectionManager.selectionText);
+}
+
 /**
  * Selects all text within the terminal.
  */