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(core): correctly reset PTE list counts after non-numbered lists and in sublists #7506

Merged
merged 2 commits into from
Sep 16, 2024

Conversation

phattran2905
Copy link
Contributor

Description

I find that the numbered list is incorrectly indexed in two places.

Case 1: On Sub-list items

The indices of list items starting at level 2 to level 9 do not start over even though they are separate lists. Instead, they continue on the counter from the previous list. This is already mentioned at #6879.

Before
1. L1
  a. L2
    i. L3
2. L1
  b. L2 // This is supposed to be 'a.'
    ii.L3 // This is supposed to be 'i.'
After
1. L1
  a. L2
    i. L3
2. L1
  a. L2
    i.L3

Case 2: Created right after a bullet list

If a numbered list is created right after a bullet list, the indices continue from the previous list counter. It is caused by using the counter-reset instead of counter-set, making the reset step ineffective.

Before
1. L1
2. L1
Some random text
● Bullet list item 1
● Bullet list item 2
3. L1 // This is supposed to reset to '1'
4. L1 // This is supposed to '2'
After
1. L1
2. L1
Some random text
● Bullet list item 1
● Bullet list item 2
1. L1
2. L1

What to review

Overall, the counter is initialized under the .pt-editable element and will be reset to 0 at every element that is not a numbered list item. In addition, the counter increases by 1 at each numbered list item until the list ends. On the other hand, it resets the counter for elements not part of the numbered list.

In order to fix Case 1, I removed the code on line:98 and let the rule set for non-numbered list items take effect on bullet list items as well.

In order to fix Case 2, I decided to target the level 1 list item and reset the counter all levels between 2 - 9.

Testing

I test it manually by creating various lists which have multi-level nested items. In addition, I intend to add more different block elements between the lists to ensure the counter is correct.

Notes for release

Copy link

vercel bot commented Sep 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
page-building-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 16, 2024 7:15am
performance-studio ✅ Ready (Inspect) Visit Preview Sep 16, 2024 7:15am
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 16, 2024 7:15am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Sep 16, 2024 7:15am

Copy link

vercel bot commented Sep 14, 2024

@phattran2905 is attempting to deploy a commit to the Sanity Sandbox Team on Vercel.

A member of the Team first needs to authorize it.

@christianhg
Copy link
Contributor

This is fantastic. Thanks a lot! I just made a small amendment (fixup) to make the diff even smaller.

@christianhg christianhg changed the title fix(core): reset counter on the PTE numbered sub-list items fix(core): correctly reset PTE list counts after non-numbered lists and in sublists Sep 16, 2024
@christianhg christianhg added this pull request to the merge queue Sep 16, 2024
Merged via the queue into sanity-io:next with commit 4918a9e Sep 16, 2024
21 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants