Skip to content

Commit ae2c2f3

Browse files
committed
Fixed copy event in IE11
1 parent 9ab0455 commit ae2c2f3

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/handlers/Clipboard.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,16 @@ function prepareTextForClipboard(text) {
3535
* Binds copy functionality to the given terminal.
3636
* @param {ClipboardEvent} ev The original copy event to be handled
3737
*/
38-
function copyHandler (ev) {
38+
function copyHandler(ev, term) {
3939
var copiedText = window.getSelection().toString(),
4040
text = prepareTextForClipboard(copiedText);
4141

42-
ev.clipboardData.setData('text/plain', text);
42+
if (term.browser.isMSIE) {
43+
window.clipboardData.setData('Text', text);
44+
} else {
45+
ev.clipboardData.setData('text/plain', text);
46+
}
47+
4348
ev.preventDefault(); // Prevent or the original text will be copied.
4449
}
4550

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

60-
var userAgent = window.navigator.userAgent.toLowerCase();
61-
if (userAgent.match(/msie|MSIE/) || userAgent.match(/(T|t)rident/)) {
65+
if (term.browser.isMSIE) {
6266
if (window.clipboardData) {
6367
var text = window.clipboardData.getData('Text');
6468
dispatchPaste(text);

src/utils/Browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let userAgent = (isNode) ? 'node' : navigator.userAgent;
1616
let platform = (isNode) ? 'node' : navigator.platform;
1717

1818
export let isFirefox = !!~userAgent.indexOf('Firefox');
19-
export let isMSIE = !!~userAgent.indexOf('MSIE');
19+
export let isMSIE = !!~userAgent.indexOf('MSIE') || !!~userAgent.indexOf('Trident');
2020

2121
// Find the users platform. We use this to interpret the meta key
2222
// and ISO third level shifts.

0 commit comments

Comments
 (0)