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

Input Interaction: set caret correctly on merge forward (Delete) #15599

Merged
merged 2 commits into from
May 14, 2019

Conversation

ellatrix
Copy link
Member

@ellatrix ellatrix commented May 13, 2019

Description

Probably regressed in #14640. The problem is that we are just assuming that the caret is in block B when merging blocks, while it could be in either. I updated the code to look which block is selected.

How has this been tested?

Merge two paragraph blocks with the Delete key (or Fn+Delete for Mac). Caret should be at merge point.

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 [Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... [Package] Block editor /packages/block-editor labels May 13, 2019
@ellatrix ellatrix requested review from youknowriad and aduth May 13, 2019 16:09
@youknowriad
Copy link
Contributor

So if I'm reading properly, this doesn't need to be backported to WP 5.2 as the culprit PR is not included in it right?

@ellatrix
Copy link
Member Author

@youknowriad I guess you're right, if the full Gutenberg release will not be included in WordPress 5.2.1.

@ellatrix
Copy link
Member Author

It should probably still be included in the Gutenberg release.

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Looks good. Works well 👍

In the course of testing this, I discovered another (unrelated) issue: #15604

packages/block-editor/src/store/effects.js Show resolved Hide resolved
const blockBType = getBlockType( blockB.name );
const { clientId, attributeKey, offset } = getSelectionStart( state );
const hasSelection = clientId === clientIdA || clientId === clientIdB;
Copy link
Member

Choose a reason for hiding this comment

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

The problem is that we are just assuming that the caret is in block B when merging blocks, while it could be in either.

I guess more accurately: It could be either, or neither? Which to me sounds like a reasonable qualification to consider, since I should be able to call mergeBlocks on any two blocks, selected or otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that's why I added the hasSelection check. If none of the blocks have selection, the caret replacement will be skipped.

updatedAttributes[ newAttributeKey ] = newHtml;

dispatch( selectionChange(
blockA.clientId,
Copy link
Member

Choose a reason for hiding this comment

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

Am I correct in thinking: While the selection may be within one or the other (or neither) of the two blocks, the merge will result in the first block becoming selected (if a selection had existed previously).

Copy link
Member Author

Choose a reason for hiding this comment

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

Should it? I didn't think much about it. If there was no selection previously, there's no selection to be merged?

@youknowriad youknowriad added this to the 5.7 (Gutenberg) milestone May 14, 2019
@gziolo gziolo added the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label May 14, 2019
@gziolo
Copy link
Member

gziolo commented May 14, 2019

So if I'm reading properly, this doesn't need to be backported to WP 5.2 as the culprit PR is not included in it right?

I added the label Backport to WP Core.

@youknowriad
Copy link
Contributor

@gziolo Actually, we don't need this label here because this bug is not on WP 5.2

@gziolo gziolo removed the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label May 14, 2019
@ellatrix ellatrix merged commit 5963776 into master May 14, 2019
@ellatrix ellatrix deleted the fix/merge-forward branch May 14, 2019 10:14
@hypest
Copy link
Contributor

hypest commented May 15, 2019

👋 , feel free to update or close #15619 if this PR fixes it, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... [Package] Block editor /packages/block-editor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants