Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/handlers/Clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ function prepareTextForClipboard(text) {
* Binds copy functionality to the given terminal.
* @param {ClipboardEvent} ev The original copy event to be handled
*/
function copyHandler (ev) {
function copyHandler(ev, term) {
var copiedText = window.getSelection().toString(),
text = prepareTextForClipboard(copiedText);

ev.clipboardData.setData('text/plain', text);
if (term.browser.isMSIE) {
window.clipboardData.setData('Text', text);
} else {
ev.clipboardData.setData('text/plain', text);
}

ev.preventDefault(); // Prevent or the original text will be copied.
}

Expand All @@ -57,8 +62,7 @@ function pasteHandler(ev, term) {
return term.cancel(ev);
};

var userAgent = window.navigator.userAgent.toLowerCase();
if (userAgent.match(/msie|MSIE/) || userAgent.match(/(T|t)rident/)) {
if (term.browser.isMSIE) {
if (window.clipboardData) {
var text = window.clipboardData.getData('Text');
dispatchPaste(text);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/Browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let userAgent = (isNode) ? 'node' : navigator.userAgent;
let platform = (isNode) ? 'node' : navigator.platform;

export let isFirefox = !!~userAgent.indexOf('Firefox');
export let isMSIE = !!~userAgent.indexOf('MSIE');
export let isMSIE = !!~userAgent.indexOf('MSIE') || !!~userAgent.indexOf('Trident');

// Find the users platform. We use this to interpret the meta key
// and ISO third level shifts.
Expand Down
5 changes: 3 additions & 2 deletions src/xterm.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,12 +447,13 @@ Terminal.prototype.initGlobal = function() {
Terminal.bindBlur(this);

// Bind clipboard functionality
on(this.element, 'copy', copyHandler);
on(this.element, 'copy', function (ev) {
copyHandler.call(this, ev, term);
});
on(this.textarea, 'paste', function (ev) {
pasteHandler.call(this, ev, term);
});


function rightClickHandlerWrapper (ev) {
rightClickHandler.call(this, ev, term);
}
Expand Down