Explore adding checks to only filter pasted fragment, rather than all of the editor's content #302
Replies: 2 comments
-
On second thought, the block keys wouldn't be enough since they stay identical when inserting content within a block. It might be possible to compare the blocks by reference (since they are built with Immutable.js). I'm not too sure this is worth the added complexity though, in particular what kind of further filtering this would allow, and how useful this filtering would be:
|
Beta Was this translation helpful? Give feedback.
-
On further thought, I think the best way to approach this would simply be to override https://github.com/facebook/draft-js/blob/master/src/model/encoding/convertFromHTMLToContentBlocks.js from Draft.js, via |
Beta Was this translation helpful? Give feedback.
-
It would be nice if the filters only operated on the pasted content, rather than everything that's inside the editor.
What is the current behavior?
At the moment,
filterEditorState
(or equivalent) is called inside of theonChange
handler with all of the editor's state as a parameter. This means the filters have to limit themselves so they won't filter out content previously entered by the user, outside of the copy-paste action.What is the expected behavior?
If the filters were only operating on the pasted content, it would be possible to preserve more formatting, and to filter out more unwanted rich text. For example, removing empty blocks at the start of the pasted content.
I'm not sure this is actually possible though. The
onChange
handler has access to both the current and previous editor state, so when the last change isinsert-fragment
it might be able to compare the ContentState before/after (say the block keys), and figure out content was inserted to then filter it.Beta Was this translation helpful? Give feedback.
All reactions