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

Block API: Pasting content that results in a new block shouldn't be treated as inline content. #19084

Merged
merged 4 commits into from
Dec 21, 2019

Conversation

pento
Copy link
Member

@pento pento commented Dec 12, 2019

Description

When pasting text, the paste handler currently assumes that if the text doesn't have a line break, and it results in one block, it can be treated as inline text, instead.

This may be correct for core, but is not necessarily correct for plugins that may wish to transform a single line of text into a custom block.

This PR tightens the paste handler assumption to only allow a selection of blocks to be treated as an inline paste.

Fixes #18390.

How has this been tested?

Tested with the sample plugin in #18390.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@pento pento added [Type] Bug An existing feature does not function as intended [Feature] Paste labels Dec 12, 2019
@pento pento self-assigned this Dec 12, 2019
@ellatrix
Copy link
Member

Could some sort of test be added?

@pento
Copy link
Member Author

pento commented Dec 13, 2019

The new supports.pasteTextInline property defaults to false, so blocks will need to opt-in to being overridden when pasting inline text.

I've added some tests, too.

@ellatrix
Copy link
Member

@pento I marked pasteTextInline as an unstable API as I'm not expecting any non core blocks to use this feature (as you have noted yourself). Let's see if there are more cases popping up.

Copy link
Member

@ellatrix ellatrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, this makes sense! :)

@ellatrix ellatrix merged commit 03928a5 into master Dec 21, 2019
@ellatrix ellatrix deleted the fix/18390-pasting-single-lines branch December 21, 2019 18:28
@youknowriad youknowriad added this to the Gutenberg 7.2 milestone Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Paste [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Block API: pasteHandler() incorrectly treats single-line pastes as inline content.
3 participants