Plugin handlePastedText doesn't get called when setting stripPastedStyles=false
quirinpa opened this issue · comments
Describe the bug
I'm trying to write a plugin to limit maximum content length in the draftail editor. I also want to be able to paste formatted content from outside the editor. Turns out my plugin's handlePastedText does not get called when setting prop stripPastedStyles to false. Unless I paste plain text.
Environment
Current version of draftail + draft.js 0.10.5
Steps to reproduce
- First, write a plugin that uses handlePastedText and use it in draftail
- Then, set editor prop stripPastedStyles to false
- Finally, handlePastedText is not called when pasting something other than plain text
Expected behavior
I expect my plugin's handlePastedText to be called
Actual behavior
It never gets called (because draftail precedes it in handling the event)
Aditional tests
I've checked out the code in the editor which does handlePastedText and copied handleDraftEditorPastedText to my plugin's handler and I've removed the prop stripPastedStyles from the editor. Then I copy html to the editor and see that it does not have formatting if I copy from outside the editor. PastedState = handleDraftEditorPastedText(html, editorState) is falsey. I add back stripPastedStyles=false and the formatting works again. I thought I'd use stripPastedStyles=true and handle the pasting of formatted content inside my plugin's handler but this does not prove to be working. I've also used draftjs-import-html to actually have some sort of formatted content but I find it very lacking in comparison to default draftail behavior. Ideally I want to pass stripPastedStyles=false and still have my plugin's code handle the paste.
I believe this could likely be fixed by following the exact same approach as #445. I’d happily review a pull request attempting this, with the needed implementation changes, unit tests, and demo code for manual testing.