Skip to content

Commit

Permalink
Fix bug #329: Copy-pasting does not work on IE11
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoran Brondsema committed Feb 16, 2016
1 parent 9e50f5b commit b4c46c3
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/js/utils/paste-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ export function setClipboardCopyData(copyEvent, editor) {
const {result: plain} =
new TextRenderer({unknownCardHandler, unknownAtomHandler}).render(mobiledoc);

clipboardData.setData(MIME_TEXT_PLAIN, plain);
clipboardData.setData(MIME_TEXT_HTML, html);
if (clipboardData && clipboardData.setData) {
clipboardData.setData(MIME_TEXT_PLAIN, plain);
clipboardData.setData(MIME_TEXT_HTML, html);
} else if (window.clipboardData && window.clipboardData.setData) { // IE
window.clipboardData.setData('Text', html);
}
}

/**
Expand All @@ -62,13 +66,23 @@ export function setClipboardCopyData(copyEvent, editor) {
*/
export function parsePostFromPaste(pasteEvent, builder, plugins=[]) {
let post;
let html = pasteEvent.clipboardData.getData(MIME_TEXT_HTML);
let html;
let text;

if (!html || html.length === 0) { // Fallback to 'text/plain'
let text = pasteEvent.clipboardData.getData(MIME_TEXT_PLAIN);
post = parsePostFromText(text, builder, plugins);
} else {
if (pasteEvent.clipboardData && pasteEvent.clipboardData.getData) {
html = pasteEvent.clipboardData.getData(MIME_TEXT_HTML);

if (!html || html.length === 0) { // Fallback to 'text/plain'
text = pasteEvent.clipboardData.getData(MIME_TEXT_PLAIN);
}
} else if (window.clipboardData && window.clipboardData.getData) { // IE
html = window.clipboardData.getData('Text');
}

if (html && html.length > 0) {
post = parsePostFromHTML(html, builder, plugins);
} else if (text && text.length > 0) {
post = parsePostFromText(text, builder, plugins);
}

return post;
Expand Down

0 comments on commit b4c46c3

Please sign in to comment.