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

fix #22550 and allow enter to insert line breaks even if template is locked #23330

Merged
merged 3 commits into from
Jul 27, 2020

Conversation

oxyc
Copy link
Member

@oxyc oxyc commented Jun 20, 2020

Description

See #22550. I have no idea what I'm doing, I'm just opening up this PR for discussion and the off chance that this is actually okay. Ping @ellatrix or someone who actually knows what's happening in this flow should have a look.

Note that this is how it used to work at least some versions back.

How has this been tested?

  1. Added a template to the post post type.
add_action('init', function () {
    $post_type_object = get_post_type_object('post');
    $post_type_object->template = [
      [ 'core/paragraph', [
        'placeholder' => 'test'
      ] ],
      [ 'core/list', [
        'placeholder' => 'test'
      ] ],
    ];
    $post_type_object->template_lock = 'all';
});
  1. Pressed enter and shift-enter to check that both add a soft line break.
  2. Press backspace and ensure the block is not removed.

Screenshots

Types of changes

Bug fix (non-breaking change which fixes an issue)

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.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@oxyc oxyc changed the title fix #22550 and allow enter to insert line breaks in richtext fix #22550 and allow enter to insert line breaks even if template is locked Jun 20, 2020
@oxyc oxyc added [Feature] Templates API Related to API powering block template functionality in the Site Editor [Type] Bug An existing feature does not function as intended [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Package] Block editor /packages/block-editor labels Jun 20, 2020
@@ -1,5 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`cpt locking template_lock all should insert line breaks when using enter and shift-enter 1`] = `
"<!-- wp:image -->
Copy link
Member

@ellatrix ellatrix Jul 27, 2020

Choose a reason for hiding this comment

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

Ideally would be best to not have content from the previous test. Not a blocker though. :)

'.block-editor-block-list__block[data-type="core/paragraph"]'
);
await page.keyboard.type( 'First line' );
await pressKeyTimes( 'Enter', 1 );
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that this should work for Enter too. Only Shift+Enter is kind of known for inserting a soft line break.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd disagree lots of my clients are not aware of that and silently treating Enter as a soft line break is a much nicer UX if you have an entire post type locked. This is also how it used to work before the regression.

Choose a reason for hiding this comment

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

Not sure if this is the right place to post, but I would like to agree with @ocean90 and have this reverted to only apply to Shift+Enter. I'm not sure what pressing Enter did in the past, but what it should do is exit the block, like it does when pushing Enter after any other paragraph block.

Choose a reason for hiding this comment

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

Just as a use case, I'm setting up a simple block which allows someone to enter one paragraph, and display an icon beside it (using the ACF plugin with InnerBlocks locked to one paragraph, and an image field).

This works fine, but I keep hitting enter after that paragraph so that I can type a normal paragraph, and instead end up with a line break inside the original block.

@ellatrix ellatrix merged commit 47dabf0 into WordPress:master Jul 27, 2020
@github-actions github-actions bot added this to the Gutenberg 8.7 milestone Jul 27, 2020
@ocean90 ocean90 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 Jul 27, 2020
youknowriad pushed a commit that referenced this pull request Jul 27, 2020
…locked (#23330)

* fix #22550 and allow enter to insert line breaks in richtext

* add e2e test

* Restore isSelected condition

Co-authored-by: Ella van Durpe <[email protected]>
@youknowriad youknowriad 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 Jul 27, 2020
@oxyc oxyc deleted the fix-enter-locked branch July 20, 2022 10:36
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] Templates API Related to API powering block template functionality in the Site Editor [Package] Block editor /packages/block-editor [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants