]> git.proxmox.com Git - mirror_xterm.js.git/blobdiff - src/xterm.js
Merge pull request #670 from Tyriar/207_selection_manager
[mirror_xterm.js.git] / src / xterm.js
index 2d74a2d50c9f1f75999739bcbbfa5fe0d67acba1..a476fd7eb0973bc7deacd9a5efb0e4ca9f65dd04 100644 (file)
@@ -251,6 +251,10 @@ function Terminal(options) {
   while (i--) {
     this.lines.push(this.blankLine());
   }
+  // Ensure the selection manager has the correct buffer
+  if (this.selectionManager) {
+    this.selectionManager.setBuffer(this.lines);
+  }
 
   this.tabs;
   this.setupStops();
@@ -522,7 +526,12 @@ Terminal.prototype.initGlobal = function() {
 
   // Bind clipboard functionality
   on(this.element, 'copy', event => {
-    copyHandler(event, term, term.selectionManager);
+    // If mouse events are active it means the selection manager is disabled and
+    // copy should be handled by the host program.
+    if (this.mouseEvents) {
+      return;
+    }
+    copyHandler(event, term, this.selectionManager);
   });
   const pasteHandlerWrapper = event => pasteHandler(event, term);
   on(this.textarea, 'paste', pasteHandlerWrapper);
@@ -687,7 +696,7 @@ Terminal.prototype.open = function(parent, focus) {
 
   this.charMeasure = new CharMeasure(document, this.helperContainer);
   this.charMeasure.on('charsizechanged', function () {
-    self.updateCharSizeCSS();
+    self.updateCharSizeStyles();
   });
   this.charMeasure.measure();
 
@@ -767,10 +776,10 @@ Terminal.loadAddon = function(addon, callback) {
  * Updates the helper CSS class with any changes necessary after the terminal's
  * character width has been changed.
  */
-Terminal.prototype.updateCharSizeCSS = function() {
+Terminal.prototype.updateCharSizeStyles = function() {
   this.charSizeStyleElement.textContent =
       `.xterm-wide-char{width:${this.charMeasure.width * 2}px;}` +
-      `.xterm-normal-char{width:${this.charMeasure.width}px;}`
+      `.xterm-normal-char{width:${this.charMeasure.width}px;}`;
 }
 
 /**
@@ -1364,6 +1373,28 @@ 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.getSelection = function() {
+  return this.selectionManager.selectionText;
+}
+
+/**
+ * Clears the current terminal selection.
+ */
+Terminal.prototype.clearSelection = function() {
+  this.selectionManager.clearSelection();
+}
+
 /**
  * Selects all text within the terminal.
  */