Skip to content

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

Merged
ellatrix merged 2 commits into
masterfrom
fix/merge-forward
May 14, 2019
Merged

ellatrix merged 2 commits into
masterfrom
fix/merge-forward

Conversation

@ellatrix

@ellatrix ellatrix commented May 13, 2019 •

Copy link
Copy Markdown
Member

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 aduth and youknowriad May 13, 2019 16:09
@youknowriad

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member Author

It should probably still be included in the Gutenberg release.

@aduth aduth left a comment

Copy link
Copy Markdown
Member

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

const blockB = getBlock( state, clientIdB );
const blockBType = getBlockType( blockB.name );
const { clientId, attributeKey, offset } = getSelectionStart( state );
const hasSelection = clientId === clientIdA || clientId === clientIdB;

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

@aduth aduth mentioned this pull request May 13, 2019
5 tasks done
@youknowriad youknowriad added this to the 5.7 (Gutenberg) milestone May 14, 2019
@gziolo

gziolo commented May 14, 2019

Copy link
Copy Markdown
Member

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
Copy Markdown
Contributor

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

@ellatrix
ellatrix merged commit 5963776 into master May 14, 2019
@ellatrix
ellatrix deleted the fix/merge-forward branch May 14, 2019 10:14
@hypest

hypest commented May 15, 2019

Copy link
Copy Markdown
Contributor

👋 , 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