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: fix tree output after applying format #14555

Merged
merged 3 commits into from
Apr 23, 2019

Conversation

ellatrix
Copy link
Member

@ellatrix ellatrix commented Mar 21, 2019

Description

Fixes #12314. Still needs some additional tests.

Problem: Applying a format around an existing format (greater selection), will chop the applied format into 2-3 pieces. Why? Because the format is just added at the end of each format array at every index:

     1111
111110000
link bold
     link

Instead, this should be:

     0000
111111111
link bold
     link

Solution: check the position at which to insert first. This should be the lowest value between the start and end indices.

How has this been tested?

Make something bold. Select the bolded text, including something more. Now link it. The link should not be split into two elements.

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 the [Package] Rich text /packages/rich-text label Mar 21, 2019
@ellatrix ellatrix added this to the 5.4 (Gutenberg) milestone Mar 21, 2019
@ellatrix ellatrix added [Status] In Progress Tracking issues with work in progress Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code and removed [Status] In Progress Tracking issues with work in progress labels Mar 21, 2019
@ellatrix ellatrix added the [Type] Bug An existing feature does not function as intended label Mar 28, 2019
@ellatrix ellatrix force-pushed the fix/rich-text-html-output branch from a55ce96 to 936cfcd Compare April 4, 2019 07:42
Copy link
Contributor

@draganescu draganescu left a comment

Choose a reason for hiding this comment

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

I tested locally and it solves the problem as described. Reading the code I don't spot any problem.
Minor thing @ellatrix while the solution here solves the problem there is another inconsistent behavior:

  • in a selection containing test text <b>bold item</b><em>italic!</em> applying a link results in <a href='#'>test text <b>bold item</b><em>italic!</em></a>
  • YET in a selection containing only<b>bold item</b> applying a link results in <b><a href='#'>bold item</a></b>

However I am unsure if this is in the scope of this fix, so I say we merge this as it is.

@ellatrix
Copy link
Member Author

@draganescu Thanks for reviewing! I don't see a problem there, what's wrong with the second case?

@draganescu draganescu merged commit c1a36fc into master Apr 23, 2019
@draganescu
Copy link
Contributor

@ellatrix it might not be a problem, the difference is that in the first case the link tags wrap the content and any tags, and in the second case the link tag is placed inside the outer tag. It just doesn't work the same, maybe it doesn't have to, I just noticed :) otherwise no issue.

@gziolo gziolo deleted the fix/rich-text-html-output branch April 23, 2019 12:14
@ellatrix
Copy link
Member Author

Thanks @draganescu. I didn't really think much of it, but you have a point. Maybe the rule for applying tags should be: wrap as much content as possible. Currently it seems to be: wrap as little content as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code [Package] Rich text /packages/rich-text [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Applied formats should produce optimized HTML
4 participants