From e39c4a6ee51ebe007886ec6f12bfb5ee39353c15 Mon Sep 17 00:00:00 2001 From: Steve Eberhardt <9057412+melchiar@users.noreply.github.com> Date: Fri, 5 Apr 2019 03:11:42 -0700 Subject: [PATCH] added disableStyleCopyPaste property (#5590) --- HEADER.js | 9 +++++++++ src/mixins/itext_key_behavior.mixin.js | 9 +++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/HEADER.js b/HEADER.js index 0b580a5eff4..be80d5069a2 100644 --- a/HEADER.js +++ b/HEADER.js @@ -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 diff --git a/src/mixins/itext_key_behavior.mixin.js b/src/mixins/itext_key_behavior.mixin.js index 0c59a410760..ed0f4e7c5fb 100644 --- a/src/mixins/itext_key_behavior.mixin.js +++ b/src/mixins/itext_key_behavior.mixin.js @@ -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 { @@ -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; },