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

RichText: stabilize onSplit #14765

Merged
merged 8 commits into from
May 18, 2019
Merged

RichText: stabilize onSplit #14765

merged 8 commits into from
May 18, 2019

Conversation

ellatrix
Copy link
Member

@ellatrix ellatrix commented Apr 2, 2019

Description

Stablizes the RichText onSplit prop.

Additionally it fixes issues where core blocks (heading and list) do not take into account any null values passed to unstableOnSplit.

How has this been tested?

Screenshots

Types of changes

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.

@ellatrix ellatrix added [Status] In Progress Tracking issues with work in progress [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable labels Apr 2, 2019
@ellatrix ellatrix mentioned this pull request Apr 2, 2019
4 tasks
@ellatrix ellatrix force-pushed the try/block-editor-selection-state branch from cbf86be to 0a85d5c Compare April 4, 2019 08:01
@ellatrix ellatrix force-pushed the try/block-editor-selection-state branch from 0a85d5c to ddc3533 Compare April 10, 2019 13:31
@ellatrix ellatrix force-pushed the try/block-editor-selection-state branch from ddc3533 to e1e6b68 Compare April 17, 2019 14:04
@ellatrix ellatrix force-pushed the try/block-editor-selection-state branch 2 times, most recently from d936b26 to 0008d0e Compare April 19, 2019 14:34
@ellatrix ellatrix changed the base branch from try/block-editor-selection-state to master April 19, 2019 14:56
@ellatrix ellatrix changed the base branch from master to try/block-editor-selection-state April 19, 2019 14:57
@ellatrix ellatrix force-pushed the try/rich-text-on-split branch from 3b721c7 to 7eca736 Compare April 19, 2019 15:09
@ellatrix ellatrix changed the base branch from try/block-editor-selection-state to master April 19, 2019 15:09
@gziolo gziolo removed this from the 5.6 (Gutenberg) milestone May 6, 2019
Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

Left some few comments, but I'm going to take this for a spin now.

*/
splitContent( blocks = [], context = {} ) {
if ( ! this.onSplit ) {
onSplit( record, pastedBlocks = [] ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be good to clarify the different use cases this function is called (sorry If it's somewhere else and I missed it), something like:

  • putting the caret in the middle of a RichText and pasting
  • click "Enter" in the middle of the text
  • other use-cases I'm not aware of?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in 199a1e9.

this.onSplit( before, after, ...blocks );
// If there are pasted blocks, set the selection to the last one.
// Otherwise, set the selection to the second block.
const indexToSelect = hasPastedBlocks ? blocks.length - 1 : 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not immediately clear to me why should we put the caret int the first block if there's no pasted blocks?

Copy link
Member Author

Choose a reason for hiding this comment

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

1 means the second block. :) After pressing enter, the caret goes in the second block (there are only two)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Alternatively this could be written as blocks.length I guess.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean the index is always blocks.length - 1 (the last block)

splitContent( blocks = [], context = {} ) {
if ( ! this.onSplit ) {
onSplit( record, pastedBlocks = [] ) {
const { onReplace, onSplit, onSplitMiddle } = this.props;
Copy link
Contributor

Choose a reason for hiding this comment

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

onSplitMiddle is not clear to me and I think it's not documented right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this something to be marked unstable?

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems good to mark as unstable for now. Will adjust.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in 199a1e9.

@youknowriad
Copy link
Contributor

Did some tests:

  • Splitting and pasting in heading and paragraph blocks are looking good with this.
  • Splitting in the list block is still "buggy" (See screenshot)
  • Pasting in the list block seems to work well

Kapture 2019-05-08 at 12 22 38

@swissspidy swissspidy changed the title RichText: stablize onSplit RichText: stabilize onSplit May 10, 2019
@ellatrix ellatrix force-pushed the try/rich-text-on-split branch from b68e141 to 7af898f Compare May 14, 2019 11:06
@ellatrix
Copy link
Member Author

@youknowriad I can't reproduce that issue. What browser are you using?

@youknowriad
Copy link
Contributor

@ellatrix I'm using Firefox

@ellatrix
Copy link
Member Author

@youknowriad It looks like it's a visual glitch that happens in master as well.

@youknowriad
Copy link
Contributor

@ellatrix I confirm, let's fix this bug separately.

@ellatrix
Copy link
Member Author

@youknowriad Addressed your feedback. Additionally, #14846 seems to fix the issue you're having in Firefox.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

Great work

@ellatrix ellatrix merged commit eddd4fc into master May 18, 2019
@ellatrix ellatrix deleted the try/rich-text-on-split branch May 18, 2019 17:02
@ellatrix
Copy link
Member Author

Thanks @youknowriad!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code
Projects
None yet
3 participants