diff --git a/src/handlers/Clipboard.js b/src/handlers/Clipboard.js index e3ad870438..1cb07ebbd1 100644 --- a/src/handlers/Clipboard.js +++ b/src/handlers/Clipboard.js @@ -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. } @@ -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); diff --git a/src/utils/Browser.js b/src/utils/Browser.js index 5240afadf1..47b756eca5 100644 --- a/src/utils/Browser.js +++ b/src/utils/Browser.js @@ -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. diff --git a/src/xterm.js b/src/xterm.js index b4ccf11572..f4e366da2b 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -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); }