Skip to content

Commit

Permalink
Revert relying on clipboardData html
Browse files Browse the repository at this point in the history
When pasting across applications (ex. IE11 -> Chrome) clipboardData html
contains <script> and <style> tags. The browser's native paste resolves
stripping the former and other unnecessary tags (<title>) and applying
appropriate styles to nodes. We should not reimplement all of this.

Fixes #886
  • Loading branch information
jhchen committed Aug 29, 2016
1 parent c191a7e commit 0c903eb
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions modules/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,16 @@ class Clipboard extends Module {
let range = this.quill.getSelection();
let delta = new Delta().retain(range.index).delete(range.length);
let types = e.clipboardData ? e.clipboardData.types : null;
if ((types instanceof DOMStringList && types.contains("text/html")) ||
(types && types.indexOf && types.indexOf('text/html') !== -1)) {
this.container.innerHTML = e.clipboardData.getData('text/html');
paste.call(this);
e.preventDefault();
} else {
let bodyTop = document.body.scrollTop;
this.container.focus();
setTimeout(() => {
paste.call(this);
document.body.scrollTop = bodyTop;
this.quill.selection.scrollIntoView();
}, 1);
}
function paste() {
let bodyTop = document.body.scrollTop;
this.container.focus();
setTimeout(() => {
delta = delta.concat(this.convert());
this.quill.updateContents(delta, Quill.sources.USER);
// range.length contributes to delta.length()
this.quill.setSelection(delta.length() - range.length, Quill.sources.SILENT);
}
document.body.scrollTop = bodyTop;
this.quill.selection.scrollIntoView();
}, 1);
}
}
Clipboard.DEFAULTS = {
Expand Down

1 comment on commit 0c903eb

@benbro
Copy link
Contributor

@benbro benbro commented on 0c903eb Sep 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The types variable isn't used any more.

Please sign in to comment.