-
Notifications
You must be signed in to change notification settings - Fork 25
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
Support pasting code #10
base: master
Are you sure you want to change the base?
Conversation
Nice work! Definitely a necessary improvement. |
var newContentState = Draft.Modifier.splitBlock(contentState, selection); | ||
return Draft.EditorState.push(editorState, newContentState, 'split-block'); | ||
editorState = splitBlock(editorState); | ||
editorState = setUnstyled(editorState); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The double split-block
creates two history items on the undo stack for what's really one atomic operation.
After cmd-returning out of a code-block, you'll need to hit cmd-z (undo) twice to get back to where you were. Hopefully one day draft-js will have a convenient way of grouping operations into a single stack item.
I made helper functions insertBlockBefore
and insertBlockAfter
(current selection) for this reason which only create a single history stack item: https://gist.github.com/danneu/33eb706be229f5e4b71204b837aff822
So one idea is to use that insertBlockAfter
helper instead of the double-split. It also moves the selection to the inserted block.
Hey @whitejava are you going to update this PR with the changes requested above? Would be awesome to land this! |
When you paste code, you will get:
But I expect this:
This MR makes pasting better.