Fixed copy event in IE11

This commit is contained in:
hiro-su
2016-11-05 23:55:34 +09:00
parent 9ab0455b05
commit 5808de648b
3 changed files with 12 additions and 7 deletions
+8 -4
View File
@@ -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);