-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Blocks: Handle pressing backspace at the beginning of blocks #461
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5e4945d
Blocks: Handle the backspace at the beginning of blocks
youknowriad 7106128
replacing `childNodes[ 0 ]` with `firstChild`
youknowriad d5fc22a
Element: Rename concatChildren helper and add unit tests
youknowriad f0c34ba
Style: avoid ternary and fallback using ||
youknowriad ae4f41a
Fix merging two consecutive empty headings
youknowriad 15b70c1
Fix TinyMCE isCollapsed error when merging two blocks
youknowriad 129ffd7
Stop keydown event propagation if editor removed by merge
aduth 1b360dc
Update concatChildren to accomodate multiple children
youknowriad a2c1065
ConcatChildren: Fix unit tests
youknowriad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Element: Rename concatChildren helper and add unit tests
- Loading branch information
commit d5fc22a190499088010baab58228116228c6f25f
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,19 +67,34 @@ export function renderToString( element ) { | |
| return renderToStaticMarkup( element ); | ||
| } | ||
|
|
||
| export function concatValues( value1, value2 ) { | ||
| const toArray = value => Array.isArray( value ) ? Children.toArray( value ) : [ value ]; | ||
| /** | ||
| * Concat two React children objects | ||
| * | ||
| * @param {?Object} children1 First children value | ||
| * @param {?Object} children2 Second children value | ||
| * | ||
| * @return {Array} The concatenation | ||
| */ | ||
| export function concatChildren( children1, children2 ) { | ||
| const toArray = ( children ) => { | ||
| if ( ! children ) { | ||
| return []; | ||
| } | ||
|
|
||
| return Array.isArray( children ) ? Children.toArray( children ) : [ children ]; | ||
| }; | ||
|
|
||
| return toArray( value1 ) | ||
| .concat( toArray( value2 ) ) | ||
| .map( ( elt, index ) => { | ||
| if ( isString( elt ) ) { | ||
| return elt; | ||
| } | ||
| return [ | ||
| ...toArray( children1 ), | ||
| ...toArray( children2 ) | ||
| ].map( ( elt, index ) => { | ||
| if ( isString( elt ) ) { | ||
| return elt; | ||
| } | ||
|
|
||
| return { | ||
| ...elt, | ||
| key: index | ||
| }; | ||
| } ); | ||
| return { | ||
| ...elt, | ||
| key: index | ||
| }; | ||
| } ); | ||
| } | ||
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I was poking around at this function, and had a couple observations:
...childrens, so two or more set of children can be concatenatedtoArrayneed exist. You'd mentioned different values, but in my testingChildren.toArrayseems to handle most everything thrown at it.toArraythenmap)Do you think something like this would work?
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.
Great idea!
I've tried your version but it's not working. I'm finding the
toArrayto be necessary. I'm unsure if it may be a problem coming from another place (parser or anything), but you can easily reproduce a bug by backspacing from the start of the second test block "I imagine..."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.
Huh, yeah, I can reproduce that. Seems to be an issue at the point of calling
cloneElementon the string though. This variation seems to work okay for me: