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

[SuperEditor] Allow continuing list item sequence by typing (Resolves #1894) #2061

Merged
merged 1 commit into from
Jun 1, 2024

Conversation

angelosilvestre
Copy link
Collaborator

[SuperEditor] Allow continuing list item sequence by typing. Resolves #1894

Current behavior

Type:

1. List item

Press enter. This will result in the following:

1. List Item
2.

Delete 2. and type 2. again.

The editor doesn't convert 2. to a list item.

Other apps

Most apps do convert the 2. to a list item, allowing the user to continue the sequence. Some of them allow numbers out of sequence, like:

1. List Item
2. List Item
5.

And some of them allows starting a list with a number different from 1.

Changes in this PR

This PR adds the ability to continue the list, by typing the next number in the sequence. For example, given the list

1. List Item
2. List Item
|

Typing 3. will convert the paragraph to a list item, but typing any other number will not.

Limitations

We cannot allow starting lists with numbers different from one without major changes. The list item ordinal value is only computed and stored at the view model level. To allow starting a list with arbitrary numbers we would need to store the ordinal value directly on the node.

/// Walks backwards counting the number of ordered list items above the [listItem] with the same indentation level.
///
/// The ordinal value starts at 1.
int computeListItemOrdinalValue(ListItemNode listItem, Document document) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did this need to be extracted? Why does it need to be public?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I extracted it because I need the same computation in the reaction, which lives in another file. I extracted to avoid having the same code in two places, but I can just copy the code to there if needed.

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.

[SuperEditor] Numbered list doesn't work on manual addition of items and when number is not 1
2 participants