Skip to content

Commit

Permalink
pass formats to clipboard.convert
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen committed Jul 24, 2018
1 parent cd75377 commit 0eb507e
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions modules/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ class Clipboard extends Module {
this.matchers.push([selector, matcher]);
}

convert({ html, text }) {
const formats = this.quill.getFormat(this.quill.selection.savedRange.index);
convert({ html, text }, formats = {}) {
if (formats[CodeBlock.blotName]) {
return new Delta().insert(text, {
[CodeBlock.blotName]: formats[CodeBlock.blotName],
Expand All @@ -100,10 +99,8 @@ class Clipboard extends Module {
nodeMatches,
);
// Remove trailing newline
if (
deltaEndsWith(delta, '\n') &&
delta.ops[delta.ops.length - 1].attributes == null
) {
const { attributes } = delta.ops[delta.ops.length - 1];
if (deltaEndsWith(delta, '\n') && (attributes == null || formats.table)) {
return delta.compose(new Delta().retain(delta.length() - 1).delete(1));
}
return delta;
Expand Down Expand Up @@ -168,7 +165,8 @@ class Clipboard extends Module {
} else {
const html = e.clipboardData.getData('text/html');
const text = e.clipboardData.getData('text/plain');
const pastedDelta = this.convert({ text, html });
const formats = this.quill.getFormat(range.index);
const pastedDelta = this.convert({ text, html }, formats);
debug.log('onPaste converted', pastedDelta, { text, html });
delta = delta.concat(pastedDelta);
}
Expand Down

0 comments on commit 0eb507e

Please sign in to comment.