Merge pull request #339 from hiro-su/fix-ie11-copy-event

Fixed copy event in IE11
This commit is contained in:
Paris Kasidiaris
2016-11-05 15:27:50 +00:00
committed by GitHub
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);
+1 -1
View File
@@ -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.
+3 -2
View File
@@ -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);
}