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

RichText: List: Fix indent/outdent #12667

Merged
merged 15 commits into from
Jan 28, 2019
Merged

Conversation

ellatrix
Copy link
Member

@ellatrix ellatrix commented Dec 7, 2018

Description

Currently in some cases indenting and outdenting list items is broken.

list-mce

This PR fixes some issues and uses the RichText value directly instead of using the editor commands.

list-indent

How has this been tested?

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.

@ellatrix ellatrix added [Status] In Progress Tracking issues with work in progress [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable labels Dec 7, 2018
@ellatrix ellatrix force-pushed the try/list-use-value-indent-outdent branch from 25c3046 to 794c90e Compare December 8, 2018 16:51
@ellatrix ellatrix force-pushed the try/list-use-value-indent-outdent branch from 794c90e to 2f4b56b Compare January 9, 2019 12:07
@ellatrix
Copy link
Member Author

I'm still adding inline documentation for these changes.

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.

Functionally, it seems to work quite well.

The code could very much use some commenting, as it's difficult to follow.

lib/packages-dependencies.php Outdated Show resolved Hide resolved
packages/editor/src/components/rich-text/list-edit.js Outdated Show resolved Hide resolved

let changed;

for ( let index = startIndex + 1 || 0; index < length; index++ ) {
Copy link
Member

Choose a reason for hiding this comment

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

When would || 0 ever take effect? The only situation I see is when the left-hand is 0 which... would produce the same result anyways.

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 think startIndex could be undefined. In any case needs commenting.

packages/rich-text/src/change-list-type.js Outdated Show resolved Hide resolved
packages/rich-text/src/indent-list-items.js Outdated Show resolved Hide resolved
packages/rich-text/src/indent-list-items.js Outdated Show resolved Hide resolved
@ellatrix
Copy link
Member Author

The code could very much use some commenting, as it's difficult to follow.

Very well aware :) That's why I commented earlier and it's still a WIP.

@ellatrix ellatrix force-pushed the try/list-use-value-indent-outdent branch from b008ba8 to 360e6dc Compare January 25, 2019 08:23
@youknowriad
Copy link
Contributor

capture d ecran 2019-01-25 a 5 00 51 pm

I had this error once when I was using the indent/outdent buttons.
I still don't know the exact steps to reproduce but thought I'd share.

@youknowriad
Copy link
Contributor

Not sure if easy, but would love a fix for "Shift + Enter" but it could be good for a separate PR too.

Aside the error that I can't reproduce anymore (fine to ignore if you don't know the potential cause), everything is good when using the list block.

Copy link
Contributor

@mcsf mcsf left a comment

Choose a reason for hiding this comment

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

So far testing looks good. I've done a first pass as I familiarise myself with this. Will be back. :)

packages/rich-text/src/test/change-list-type.js Outdated Show resolved Hide resolved
/**
* Indents any selected list items if possible.
*
* @param {Object} value Value to change.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a type defined in JSDoc for rich text? If not, should we?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, not so far. Perhaps we can look into that separately.

tagName,
value,
onChange,
} ) => (
Copy link
Contributor

Choose a reason for hiding this comment

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

Slightly tangential to the PR, but I would've expected the relationship between RichText and the List block to be more like:

List#edit = ( … ) =>
  <ListEdit>
    <RichText />
  </ListEdit>

rather than let RichText conditionally render ListEdit among its children based its own state and props (isSelected && this.multilineTag === 'li'). It feels like a strange burden on RichText and adds some indirection that reminds me of React/Backbone mixins, since List#edit has to remember to pass onTagNameChange to RichText. Also, I wonder why we need to generalise onTagNameChange instead of letting ListEdit implement specific logic for ul and ol.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good to rethink, but I feel like it might be better to do separately because we leave most of this unchanged.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed

@@ -87,8 +87,6 @@ function register_tinymce_scripts() {
gutenberg_override_script( 'wp-tinymce-root', includes_url( 'js/tinymce/' ) . "tinymce{$mce_suffix}.js", array(), $tinymce_version );
gutenberg_override_script( 'wp-tinymce', includes_url( 'js/tinymce/' ) . "plugins/compat3x/plugin{$suffix}.js", array( 'wp-tinymce-root' ), $tinymce_version );
}

gutenberg_override_script( 'wp-tinymce-lists', includes_url( 'js/tinymce/' ) . "plugins/lists/plugin{$suffix}.js", array( 'wp-tinymce' ), $tinymce_version );
Copy link
Member

Choose a reason for hiding this comment

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

FYI: This line will separately become removed in #13466.

Copy link
Member Author

Choose a reason for hiding this comment

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

What's the process of removing core PHP related to Gutenberg PRs?

Copy link
Member

Choose a reason for hiding this comment

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

What's the process of removing core PHP related to Gutenberg PRs?

I'm currently gutting most of the PHP, so that we'll get to a point where Gutenberg PHP is primarily just overrides to the default core scripts and block implementations.

See also:

@ellatrix ellatrix force-pushed the try/list-use-value-indent-outdent branch from ca99c91 to e4dc45d Compare January 28, 2019 10:33
@youknowriad
Copy link
Contributor

I'm noticing some issues on Firefox.

  • Backspace is behaving weirdly, especially for indented lists
  • Sometimes I get this error

capture d ecran 2019-01-28 a 3 13 55 pm

  • Sometimes, typing is stuck, for instance. Create this list:
- level 1
     - level 2

and then put the caret after "level 1", type Enter and try typing anything.

@ellatrix
Copy link
Member Author

Backspace is behaving weirdly, especially for indented lists

When is it behaving weirdly. Steps to reproduce? Does the same thing happen on master? Worth noting that the PR shouldn't affect enter/backspace behaviour as it doesn't touch that logic.

Sometimes I get this error

Same as above

Sometimes, typing is stuck, for instance. Create this list:

Happens for master too. Let's look separately.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

I confirm I have the same list block weirdness in master. Let's follow up on that separately. Using the list block is not very good in Firefox right now.

@ellatrix
Copy link
Member Author

Thanks @youknowriad! I'll follow up with fixes for enter/backspace.

@ellatrix ellatrix merged commit 32547dd into master Jan 28, 2019
@ellatrix ellatrix deleted the try/list-use-value-indent-outdent branch January 28, 2019 16:25
youknowriad pushed a commit that referenced this pull request Jan 28, 2019
* RichText: List: use value to indent/outdent

* Add outdent

* Support multi outdent

* Hold one reference per format

* Keep list formats when indenting to new index

* Remove unneeded parameter

* Rename

* Add logic to change list type

* Add tests

* Add e2e tests

* Add some basic docs. Clean up.

* Remove duplicate wp-tinymce dependency

* Clean up

* Add more docs, fix getSelectedListNode

* Put duplicate text values in constant
@youknowriad youknowriad added this to the 5.0 (Gutenberg) milestone Jan 28, 2019
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 [Status] In Progress Tracking issues with work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants