Skip to content

Commit

Permalink
Fix cut and copy events
Browse files Browse the repository at this point in the history
- Do not actually cut on cut
- Strip trailing whitespaces on copy (fix #66)
  • Loading branch information
parisk committed Jun 5, 2016
1 parent 6472168 commit c02cc84
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/xterm.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,10 @@
* 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);
};

Expand Down Expand Up @@ -524,12 +525,26 @@
};


/*
* 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();
});
};

Expand Down

0 comments on commit c02cc84

Please sign in to comment.