Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pasted text does not get the applied style #4981

Closed
semiadam opened this issue May 19, 2018 · 9 comments
Closed

Pasted text does not get the applied style #4981

semiadam opened this issue May 19, 2018 · 9 comments
Labels
stale Issue marked as stale by the stale bot

Comments

@semiadam
Copy link

semiadam commented May 19, 2018

By design, my app does not allow rich text. Meaning that, all text styles are applied to the entire text element by applying .set() on the itext object. However, if user copy/paste some text within the itext, the applied style will not be applied to the pasted text, so I ended up having a textbox with different text styles in it (see snapshot and fiddle).

Version

2.3.0

Test Case

http://jsfiddle.net/Da7SP/1647/

Steps to reproduce

Edit text box. Select a few letters. Hit CTRL+C and CTRL+V to duplicate those letter. Click on button to change the

Expected Behavior

The entire content of textbox must get the applied style.

Actual Behavior

Pasted letter do not get the applied style.
image

@semiadam
Copy link
Author

Hello @kangax and @asturur ,
Any thoughts on this one?

@semireg
Copy link

semireg commented Aug 18, 2018

This worked for me:

document.addEventListener('keydown', this.keyHandler.keydown, false);

then...

keydown = (e: any) => { fabric.copiedTextStyle = null; }

@asturur
Copy link
Member

asturur commented Aug 19, 2018

i wonder if this should be another config options. like useStyleOnPaste?

@asturur
Copy link
Member

asturur commented Aug 19, 2018

what you can get is either segments of pasted style or no style pasted.

There are additional methods like cleanStyle that should allow you to eliminate style where possible.

@melchiar
Copy link
Member

I just encountered the same issue with my app since I'm trying to keep the styling uniform within each textbox as well. I ended up just overriding insertNewStyleBlock function like so to prevent the creation of style blocks.

fabric.Textbox.prototype.insertNewStyleBlock = function() {}

@asturur, would you be okay if I did a PR to add a config option for modifying this behavior as you suggested?

@asturur
Copy link
Member

asturur commented Mar 23, 2019

i thought we did something like that.

@asturur
Copy link
Member

asturur commented Mar 23, 2019

image

i think we can get away with a boolean disableStyleCopying property on the Text Class so that that object has an empty object or whatever it has to have to do not carry over any style?

well or a better name.

@stale
Copy link

stale bot commented Jan 26, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issue marked as stale by the stale bot label Jan 26, 2020
@stale stale bot closed this as completed Feb 2, 2020
@sponno
Copy link

sponno commented May 12, 2020

Adding this line fixes the issue
fabric.disableStyleCopyPaste = true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Issue marked as stale by the stale bot
Projects
None yet
Development

No branches or pull requests

5 participants