-
Notifications
You must be signed in to change notification settings - Fork 14
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
Spike Replacing CodeMirror with Draft-js #93
base: master
Are you sure you want to change the base?
Conversation
Spike using Draft-js for pretty-text-input, replacing CodeMirror. Very hacky right now. Doesn't propagate changes thru yet.
What about copy-paste? Is there a solution for when you select and copy text to get the value (and not the rendered label)? I can think of some goofy solutions, so I guess I should say: is there a relatively straightforward solution? |
We debounce already with CodeMirror, so is there any difference between what we do now and what we'd do with Draft.js? |
That's on my todo list! Nothing super straightforward that I'm aware of yet. At this point my solution would be to implement handlePastedText, and if it's a curly, parse the tag and call Not too bad, but what about manually typing in With a 'decorator', you can write a function to tell Draft how to match sections of text and render them with a custom component. Draft calls that function for you. Perfect. However Draft will not treat text inside of those atomically, ie you can delete single characters instead of the whole pill. So you use 'entities' instead - but I wasn't sure how to combine that with those simple text-matching decorators. May be just lack of knowledge on my part at this point. |
I guess I was worried about the round-tripping. |
Update to my comment above re copy paste: I only addressed pasting, not copying. For copy, I don't know yet! |
But that's the point of debouncing. You only round-trip on the debounce ends. So if serialization/deserialization is no more expensive than CodeMirror, then it's at least no worse than what we currently have. |
My impression is that it could be more expensive. But I'll measure. Draft-js recommends not debouncing and then triggering re-render here, to avoid interaction problems caused by things getting out of sync between the user's typing and the new state after debounce:
(emphasis added) I'm not sure if CM really 'serializes' in the sense we are talking about here. The With Draft-js, you pass a structured Serializing between And that's probably the difference between CodeMirror and Draft-js: CodeMirror is a text editor component; Draft-js is a structured content (aka 'rich text') editor. (That's just my take.) |
Re copy, this is discouraging: facebookarchive/draft-js#787
Making copying a pretty-pill from one pretty-text instance to another work might be a small science project. :( Issue above has some ideas using (We gotta make that work.) |
I'm not proposing anything that deviates from that. Internally, the editor would use normal EditorState. But it would debounce a sync of that state outside itself. That's effectively what we do now. Without that debounce, syncing CodeMirror was way too expensive for big fields. That's why I added the debounce. It's weird, but it has worked fine since then. Now, if serializing/deserializing EditorState is too expensive, then that won't work, because it will cause noticeable pauses in the UI. I'm guessing anything 200ms or higher for big fields would be where it would be dangerous. But if it stays at or under 100ms or so, we're fine. |
Yeah, I've been down the road of hooking into copy-paste, and it wasn't fun. But as usual, I remember IE being the worst offender. But even with decent browsers, yes, it is likely to be a science experiment. |
Spike using Draft-js for pretty-text-input, replacing CodeMirror.
Very hacky right now. Doesn't propagate changes thru yet.
One issue is how to propagate changes efficiently. The Draft-js
Editor
component is a controlled component, that passes anEditorState
object representing the current state of the editor, as a structured object. You can serialize between structuredEditorState
and say plain text with curlies, but that is expensive. Draft-js recommends puttingEditorState
directly in (for example) your redux store, and only serializing when persisting. We don't want to serialize back to plain text every key stroke. At a minimum we'll want to debounce. Or maybe just callonChange
with the serialized value on things like blur, tag selection.