]> git.proxmox.com Git - mirror_xterm.js.git/commitdiff
Fix cut and copy events
authorParis <paris@sourcelair.com>
Sun, 5 Jun 2016 03:35:33 +0000 (06:35 +0300)
committerParis <paris@sourcelair.com>
Sun, 5 Jun 2016 03:35:33 +0000 (06:35 +0300)
- Do not actually cut on cut
- Strip trailing whitespaces on copy (fix #66)

src/xterm.js

index d0ce8cc372a413e7caf444f4f7687ddc75cb1d3c..fc8fd3826168917388c2f1686ec1d622bc20f4f5 100644 (file)
      * Initialize default behavior
      */
     Terminal.prototype.initGlobal = function() {
-      Terminal.bindPaste(this);
       Terminal.bindKeys(this);
+      Terminal.bindPaste(this);
       Terminal.bindCopy(this);
+      Terminal.bindCut(this);
       Terminal.bindDrop(this);
     };
 
     };
 
 
-    /*
-     * Bind copy event
+    /**
+     * Bind copy event. Stript trailing whitespaces from selection.
      */
     Terminal.bindCopy = function(term) {
       on(term.element, 'copy', function(ev) {
-        return;
+        var selectedText = window.getSelection().toString(),
+                                               copiedText = selectedText.split('\n').map(function (element) {
+              return element.replace(/\s+$/g, '');
+            }).join('\n');
+        ev.clipboardData.setData('text/plain', copiedText);
+        ev.preventDefault();
+      });
+    };
+
+       /**
+        * Cancel the cut event completely
+        */
+       Terminal.bindCut = function(term) {
+      on(term.element, 'cut', function (ev) {
+        ev.preventDefault();
       });
     };