-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Merge inner blocks if wrappers are equal #43181
Conversation
Size Change: +4.04 kB (0%) Total Size: 1.27 MB
ℹ️ View Unchanged
|
f7e363f
to
37e1819
Compare
37e1819
to
e794fb3
Compare
Thanks, @ellatrix. This works really well for backward merges, but why not handle forward ones too? In the screencast below, I try to merge two lists in both directions, then two quotes in both directions: merging-consecutive-lists-quotes.mov |
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.
This is working really nicely, thanks for the follow-up.
There are still things to iterate on — like only unwrapping the selected inner block and not all of its siblings — but I'll be happy with just getting the essential merging support in 6.1.
What do you think? Does this PR need anything else right now?
Object.keys( rootAttributes ).every( | ||
( key ) => | ||
rootAttributes[ key ] === | ||
previousRootAttributes[ key ] | ||
) |
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.
You raise an interesting question here. What led you to this check? For me, the first scenario that came to mind was merging between a UL and a OL. I first expected to just merge (i.e. skip this check), but on the other hand the way that Backspace unwraps the LI first means that the next Backspace will be very obvious (merge into the prev list, regardless of UL/OL).
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.
Yes, not sure if we should keep this check or not. This is generalised for all wrapper blocks. If two quotes have an empty or same citation, they can be merged, otherwise not. If two group blocks have the same background color, they can be merged, otherwise not. But you could also make the case that we should just merge them regardless of attributes, and maybe keep the attributes of the currently selected block.
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.
If two quotes have an empty or same citation, they can be merged, otherwise not. If two group blocks have the same background color, they can be merged, otherwise not.
At the risk of overpinging, @jasmussen might be someone who cares about these details like we do. :)
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 have this feeling — and correct me if I'm off beat here — that there's already a great deal of complexity around this handling. In that light, I would err on the sake of simplicity, and only add checks when we know we need them.
In this case, by having a singular merging behavior — allowing it regardless of props set — we'd also never run into the question of "why did it work this one time, but not that other"?
Not a strong opinion, but it's one that makes me lean towards starting with less.
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.
For me that's fine if we're ok with the potential content loss. E.g. if we're merging two quotes with cites, the cite of the quote we're merging will be lost. Is that ok? I added these checks because I though that's not ok.
I don't mind either way. We can also try to remove the aggressive unwrapping in this PR. What do you think? |
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.
This is a huge improvement!! 👍
You know the machinery better, but I'd say we could feasibly improve the unwrapping in a day, right? If not, might as well merge and iterate. |
I thought it was about whether it can be included in the release or not :) |
Well, yes, that was my rationale: I'd rather prioritise getting any kind of merging into 6.1. So, unless the improved unwrapping can be added very quickly, it seems better to just merge this PR so that, in parallel, in can be backported. |
I just cherry-picked this PR to the wp/6.1 branch to get it included in the next release: 5b9c3dd |
Package updates for bug and regression fixes: @wordpress/block-directory: 3.15.6 @wordpress/block-editor: 10.0.6 @wordpress/block-library: 7.14.6 @wordpress/components: 21.0.5 @wordpress/customize-widgets: 3.14.6 @wordpress/edit-post: 6.14.6 @wordpress/edit-site: 4.14.8 @wordpress/edit-widgets: 4.14.6 @wordpress/editor: 12.16.6 @wordpress/format-library: 3.15.6 @wordpress/interface: 4.16.5 @wordpress/list-reusable-blocks: 3.15.5 @wordpress/nux: 5.15.5 @wordpress/preferences: 2.9.5 @wordpress/reusable-blocks: 3.15.6 @wordpress/server-side-render: 3.15.5 @wordpress/widgets: 2.15.6 References: * [WordPress/gutenberg#43181 Gutenberg PR 43181] - Merge inner blocks if wrappers are equal * [WordPress/gutenberg#44098 Gutenberg PR 44098] - Fix content blocks with nested blocks always appear as top level * [WordPress/gutenberg#44150 Gutenberg PR 44150] - Refresh selection styles * [WordPress/gutenberg#44415 Gutenberg PR 44415] - Removes `__unstableMaxPages` attribute from Page List and Nav blocks * [WordPress/gutenberg#44463 Gutenberg PR 44463] - Follow discussion settings in the comments block edit * [WordPress/gutenberg#44584 Gutenberg PR 44584] - Avoid querying block templates during installation * [WordPress/gutenberg#44637 Gutenberg PR 44637] - Resizable editor: Fix height setting bug * [WordPress/gutenberg#44640 Gutenberg PR 44640] - Only include theme.css if the theme declares support for wp-block-styles * [WordPress/gutenberg#44650 Gutenberg PR 44650] - Fix empty links being created for the author's name comment * [WordPress/gutenberg#44652 Gutenberg PR 44652] - Block Editor: Fix block search for non-Latin characters * [WordPress/gutenberg#44660 Gutenberg PR 44660] - Legacy Group inner block wrapper should work with constrained layout * [WordPress/gutenberg#44676 Gutenberg PR 44676] - Hide list items from content area of content locked blocks * [WordPress/gutenberg#44718 Gutenberg PR 44718] - Margin visualizer: Apply negative value to margins with `calc()` * [WordPress/gutenberg#44721 Gutenberg PR 44721] - Remove anchor support from the navigation block * [WordPress/gutenberg#44731 Gutenberg PR 44731] - Buttons: Add specificity for the editor Follow-up to [54257], [54335], and [54383]. Props bernhard-reiter, czapla, annezazu, cbravobernal, ndiego, bjorsch, nendeb55. See #56467. git-svn-id: https://develop.svn.wordpress.org/trunk@54483 602fd350-edb4-49c9-b593-d223f7449a82
Package updates for bug and regression fixes: @wordpress/block-directory: 3.15.6 @wordpress/block-editor: 10.0.6 @wordpress/block-library: 7.14.6 @wordpress/components: 21.0.5 @wordpress/customize-widgets: 3.14.6 @wordpress/edit-post: 6.14.6 @wordpress/edit-site: 4.14.8 @wordpress/edit-widgets: 4.14.6 @wordpress/editor: 12.16.6 @wordpress/format-library: 3.15.6 @wordpress/interface: 4.16.5 @wordpress/list-reusable-blocks: 3.15.5 @wordpress/nux: 5.15.5 @wordpress/preferences: 2.9.5 @wordpress/reusable-blocks: 3.15.6 @wordpress/server-side-render: 3.15.5 @wordpress/widgets: 2.15.6 References: * [WordPress/gutenberg#43181 Gutenberg PR 43181] - Merge inner blocks if wrappers are equal * [WordPress/gutenberg#44098 Gutenberg PR 44098] - Fix content blocks with nested blocks always appear as top level * [WordPress/gutenberg#44150 Gutenberg PR 44150] - Refresh selection styles * [WordPress/gutenberg#44415 Gutenberg PR 44415] - Removes `__unstableMaxPages` attribute from Page List and Nav blocks * [WordPress/gutenberg#44463 Gutenberg PR 44463] - Follow discussion settings in the comments block edit * [WordPress/gutenberg#44584 Gutenberg PR 44584] - Avoid querying block templates during installation * [WordPress/gutenberg#44637 Gutenberg PR 44637] - Resizable editor: Fix height setting bug * [WordPress/gutenberg#44640 Gutenberg PR 44640] - Only include theme.css if the theme declares support for wp-block-styles * [WordPress/gutenberg#44650 Gutenberg PR 44650] - Fix empty links being created for the author's name comment * [WordPress/gutenberg#44652 Gutenberg PR 44652] - Block Editor: Fix block search for non-Latin characters * [WordPress/gutenberg#44660 Gutenberg PR 44660] - Legacy Group inner block wrapper should work with constrained layout * [WordPress/gutenberg#44676 Gutenberg PR 44676] - Hide list items from content area of content locked blocks * [WordPress/gutenberg#44718 Gutenberg PR 44718] - Margin visualizer: Apply negative value to margins with `calc()` * [WordPress/gutenberg#44721 Gutenberg PR 44721] - Remove anchor support from the navigation block * [WordPress/gutenberg#44731 Gutenberg PR 44731] - Buttons: Add specificity for the editor Follow-up to [54257], [54335], and [54383]. Props bernhard-reiter, czapla, annezazu, cbravobernal, ndiego, bjorsch, nendeb55. See #56467. Built from https://develop.svn.wordpress.org/trunk@54483 git-svn-id: http://core.svn.wordpress.org/trunk@54042 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Package updates for bug and regression fixes: @wordpress/block-directory: 3.15.6 @wordpress/block-editor: 10.0.6 @wordpress/block-library: 7.14.6 @wordpress/components: 21.0.5 @wordpress/customize-widgets: 3.14.6 @wordpress/edit-post: 6.14.6 @wordpress/edit-site: 4.14.8 @wordpress/edit-widgets: 4.14.6 @wordpress/editor: 12.16.6 @wordpress/format-library: 3.15.6 @wordpress/interface: 4.16.5 @wordpress/list-reusable-blocks: 3.15.5 @wordpress/nux: 5.15.5 @wordpress/preferences: 2.9.5 @wordpress/reusable-blocks: 3.15.6 @wordpress/server-side-render: 3.15.5 @wordpress/widgets: 2.15.6 References: * [WordPress/gutenberg#43181 Gutenberg PR 43181] - Merge inner blocks if wrappers are equal * [WordPress/gutenberg#44098 Gutenberg PR 44098] - Fix content blocks with nested blocks always appear as top level * [WordPress/gutenberg#44150 Gutenberg PR 44150] - Refresh selection styles * [WordPress/gutenberg#44415 Gutenberg PR 44415] - Removes `__unstableMaxPages` attribute from Page List and Nav blocks * [WordPress/gutenberg#44463 Gutenberg PR 44463] - Follow discussion settings in the comments block edit * [WordPress/gutenberg#44584 Gutenberg PR 44584] - Avoid querying block templates during installation * [WordPress/gutenberg#44637 Gutenberg PR 44637] - Resizable editor: Fix height setting bug * [WordPress/gutenberg#44640 Gutenberg PR 44640] - Only include theme.css if the theme declares support for wp-block-styles * [WordPress/gutenberg#44650 Gutenberg PR 44650] - Fix empty links being created for the author's name comment * [WordPress/gutenberg#44652 Gutenberg PR 44652] - Block Editor: Fix block search for non-Latin characters * [WordPress/gutenberg#44660 Gutenberg PR 44660] - Legacy Group inner block wrapper should work with constrained layout * [WordPress/gutenberg#44676 Gutenberg PR 44676] - Hide list items from content area of content locked blocks * [WordPress/gutenberg#44718 Gutenberg PR 44718] - Margin visualizer: Apply negative value to margins with `calc()` * [WordPress/gutenberg#44721 Gutenberg PR 44721] - Remove anchor support from the navigation block * [WordPress/gutenberg#44731 Gutenberg PR 44731] - Buttons: Add specificity for the editor Follow-up to [54257], [54335], and [54383]. Props bernhard-reiter, czapla, annezazu, cbravobernal, ndiego, bjorsch, nendeb55. See #56467. Built from https://develop.svn.wordpress.org/trunk@54483 git-svn-id: https://core.svn.wordpress.org/trunk@54042 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Package updates for bug and regression fixes: @wordpress/block-directory: 3.15.6 @wordpress/block-editor: 10.0.6 @wordpress/block-library: 7.14.6 @wordpress/components: 21.0.5 @wordpress/customize-widgets: 3.14.6 @wordpress/edit-post: 6.14.6 @wordpress/edit-site: 4.14.8 @wordpress/edit-widgets: 4.14.6 @wordpress/editor: 12.16.6 @wordpress/format-library: 3.15.6 @wordpress/interface: 4.16.5 @wordpress/list-reusable-blocks: 3.15.5 @wordpress/nux: 5.15.5 @wordpress/preferences: 2.9.5 @wordpress/reusable-blocks: 3.15.6 @wordpress/server-side-render: 3.15.5 @wordpress/widgets: 2.15.6 References: * [WordPress/gutenberg#43181 Gutenberg PR 43181] - Merge inner blocks if wrappers are equal * [WordPress/gutenberg#44098 Gutenberg PR 44098] - Fix content blocks with nested blocks always appear as top level * [WordPress/gutenberg#44150 Gutenberg PR 44150] - Refresh selection styles * [WordPress/gutenberg#44415 Gutenberg PR 44415] - Removes `__unstableMaxPages` attribute from Page List and Nav blocks * [WordPress/gutenberg#44463 Gutenberg PR 44463] - Follow discussion settings in the comments block edit * [WordPress/gutenberg#44584 Gutenberg PR 44584] - Avoid querying block templates during installation * [WordPress/gutenberg#44637 Gutenberg PR 44637] - Resizable editor: Fix height setting bug * [WordPress/gutenberg#44640 Gutenberg PR 44640] - Only include theme.css if the theme declares support for wp-block-styles * [WordPress/gutenberg#44650 Gutenberg PR 44650] - Fix empty links being created for the author's name comment * [WordPress/gutenberg#44652 Gutenberg PR 44652] - Block Editor: Fix block search for non-Latin characters * [WordPress/gutenberg#44660 Gutenberg PR 44660] - Legacy Group inner block wrapper should work with constrained layout * [WordPress/gutenberg#44676 Gutenberg PR 44676] - Hide list items from content area of content locked blocks * [WordPress/gutenberg#44718 Gutenberg PR 44718] - Margin visualizer: Apply negative value to margins with `calc()` * [WordPress/gutenberg#44721 Gutenberg PR 44721] - Remove anchor support from the navigation block * [WordPress/gutenberg#44731 Gutenberg PR 44731] - Buttons: Add specificity for the editor Follow-up to [54257], [54335], and [54383]. Props bernhard-reiter, czapla, annezazu, cbravobernal, ndiego, bjorsch, nendeb55. See #56467. git-svn-id: https://develop.svn.wordpress.org/trunk@54483 602fd350-edb4-49c9-b593-d223f7449a82
Fixes #44436
What?
Allows inner blocks to be merged if the current and previous wrappers are the same (block name and attributes are equal).
Why?
This is useful in particular for lists: it allows you to merge list items into the previous list (if the list attributes are the same).
But it is also useful for other blocks like quote and group. If two quotes have the same cite (or no cite), the contents can be merged. And if two group blocks have the same attributes (e.g. same colour), the contents can be merged.
How?
Extends the
onMerge
function.Testing Instructions
There's in total 6 behaviours to test for both list and quote. Set up as following: one paragraph, two separate list blocks, and another paragraph. Undo the action after each step.
Screenshots or screencast