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 getParentIndex #13562

Merged
merged 4 commits into from
Jan 29, 2019
Merged

RichText: List: Fix getParentIndex #13562

merged 4 commits into from
Jan 29, 2019

Conversation

ellatrix
Copy link
Member

@ellatrix ellatrix commented Jan 29, 2019

Description

Fixes #13559 (comment). The bug is caused by a bug in getParentIndex. It should not consider the line index of the given index as the parent index. It is better to only accept a line index as an argument for getParentIndex, so it can be skipped reliably.

How has this been tested?

See #13559 (comment).

Screenshots

Types of changes

Bug fix

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 this to the 5.0 (Gutenberg) milestone Jan 29, 2019
@ellatrix ellatrix added the [Package] Rich text /packages/rich-text label Jan 29, 2019
@mcsf
Copy link
Contributor

mcsf commented Jan 29, 2019

Thanks for the fix, it seems to do the trick.

I have some comments on the new indentation implementation, though:

  1. In getLineIndex and getParentLineIndex:
while ( index-- ) {

Since index is provided by the function caller, I would guard this more safely with index-- <= 0.

  1. In getParentLineIndex:
if ( formatsAtIndex.length === startFormats.length - 1 ) {

Just from reading, this seems to encompass any kind of rich-text format, not just ul / ol. Is there a risk that this will fail (i.e. that we have a false-positive) for certain rich-text values if there happens to be some other format (like strong) whose edge sits right at LINE_SEPARATOR?

@ellatrix
Copy link
Member Author

Since index is provided by the function caller, I would guard this more safely with index-- <= 0.

Could you elaborate on why this is safer?

Just from reading, this seems to encompass any kind of rich-text format, not just ul / ol. Is there a risk that this will fail (i.e. that we have a false-positive) for certain rich-text values if there happens to be some other format (like strong) whose edge sits right at LINE_SEPARATOR?

I'm not sure I'm following. Could you illustrate with an example?

@ellatrix
Copy link
Member Author

Just from reading, this seems to encompass any kind of rich-text format, not just ul / ol. Is there a risk that this will fail (i.e. that we have a false-positive) for certain rich-text values if there happens to be some other format (like strong) whose edge sits right at LINE_SEPARATOR?

Ah I think I get what you mean. Formats at line separators should only be line formats like ul / ol. It's a good point to raise though. While the normal formats are ignored when building the DOM or HTML tree, they do get applied through applyFormat. We should prevent application there.

@mcsf
Copy link
Contributor

mcsf commented Jan 29, 2019

I'm not sure I'm following. Could you illustrate with an example?

Simply put, if something somewhere (plain human error, or some other unexpected evaluation) ends up calling getLineIndex( value, -1 ), the VM will break.

@mcsf
Copy link
Contributor

mcsf commented Jan 29, 2019

While the normal formats are ignored when building the DOM or HTML tree, they do get applied through applyFormat. We should prevent application there.

Great, thanks!

@ellatrix ellatrix mentioned this pull request Jan 29, 2019
5 tasks
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.

LGTM!, assuming the next PR (#13563) handles my last items of feedback.

@ellatrix
Copy link
Member Author

Simply put, if something somewhere (plain human error, or some other unexpected evaluation) ends up calling getLineIndex( value, -1 ), the VM will break.

Ah, the selection can't be negative, so I didn't add logic for it. Should I account for it?

@ellatrix ellatrix merged commit bf1c941 into master Jan 29, 2019
@ellatrix ellatrix deleted the fix/list-parent-index branch January 29, 2019 16:07
youknowriad pushed a commit that referenced this pull request Jan 29, 2019
* RichText: List: Fix getParentIndex

* Fill out test name

* Add unit tests for getParentLineIndex

* Guard against negative lineIndex
daniloercoli added a commit that referenced this pull request Jan 30, 2019
…rnmobile/372-use-RichText-on-Title-block

* 'master' of https://github.com/WordPress/gutenberg: (36 commits)
  Fixes plural messages POT generation. (#13577)
  Typo fix (#13595)
  REST API: Remove oEmbed proxy HTML filtering (#13575)
  Removed unnecessary className attribute. Fixes #11664 (#11831)
  Add changelog for RSS block (#13588)
  Components: Set type=button for TabPanel button elements. (#11944)
  Update util.js (#13582)
  Docs: Add accessbility specific page (#13169)
  Rnmobile/media methods refactor (#13554)
  chore(release): publish
  chore(release): publish
  Plugin: Deprecate gutenberg_get_script_polyfill (#13536)
  Block API: Parse entity only when valid character reference (#13512)
  RichText: List: fix indentation (#13563)
  Plugin: Deprecate window._wpLoadGutenbergEditor (#13547)
  Plugin: Avoid setting generic "Edit Post" title on load (#13552)
  Plugin: Populate demo content by default content filters (#13553)
  RichText: List: Fix getParentIndex (#13562)
  RichText: List: Fix outdent with children (#13559)
  Scripts: Remove npm run build from test-e2e default run (#13420)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Rich text /packages/rich-text
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants