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

Support pasting code #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Support pasting code #10

wants to merge 4 commits into from

Conversation

whitejava
Copy link

@whitejava whitejava commented Nov 25, 2016

When you paste code, you will get:

a

But I expect this:

ef195482-8f65-444c-9d15-89dea825817a

This MR makes pasting better.

@danneu
Copy link

danneu commented Jun 8, 2017

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);
Copy link

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.

@mxstbr
Copy link
Collaborator

mxstbr commented Sep 22, 2017

Hey @whitejava are you going to update this PR with the changes requested above? Would be awesome to land this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants