Skip to content

Commit

Permalink
added disableStyleCopyPaste property (#5590)
Browse files Browse the repository at this point in the history
  • Loading branch information
melchiar authored and asturur committed Apr 5, 2019
1 parent 876325c commit 66037c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 9 additions & 0 deletions HEADER.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ fabric.charWidthsCache = { };
*/
fabric.textureSize = 2048;

/**
* When 'true', style information is not retained when copy/pasting text, making
* pasted text use destination style.
* Defaults to 'false'.
* @type Boolean
* @default
*/
fabric.disableStyleCopyPaste = false;

/**
* Enable webgl for filtering picture is available
* A filtering backend will be initialized, this will both take memory and
Expand Down
9 changes: 7 additions & 2 deletions src/mixins/itext_key_behavior.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
}
}
if (insertedText.length) {
if (fromPaste && insertedText.join('') === fabric.copiedText) {
if (fromPaste && insertedText.join('') === fabric.copiedText && !fabric.disableStyleCopyPaste) {
this.insertNewStyleBlock(insertedText, this.selectionStart, fabric.copiedTextStyle);
}
else {
Expand Down Expand Up @@ -239,7 +239,12 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
}

fabric.copiedText = this.getSelectedText();
fabric.copiedTextStyle = this.getSelectionStyles(this.selectionStart, this.selectionEnd, true);
if (!fabric.disableStyleCopyPaste) {
fabric.copiedTextStyle = this.getSelectionStyles(this.selectionStart, this.selectionEnd, true);
}
else {
fabric.copiedTextStyle = null;
}
this._copyDone = true;
},

Expand Down

0 comments on commit 66037c7

Please sign in to comment.