facebook / lexical

Lexical is an extensible text editor framework that provides excellent reliability, accessibility and performance.
https://lexical.dev
MIT License
19.53k stars 1.65k forks source link

Feature: Lists should be toggleable #6733

Open BennyAlex opened 6 days ago

BennyAlex commented 6 days ago

Description

If you dispatch a list command like INSERT_UNORDERED_LIST_COMMAND it will not toggle a list back to normal. This is different from formatting a text with bold, italic etc.

So I want to recreate the keyboard shortcuts from word. Using Ctrl + Shift + L can toggle a list. This should be the default behavior as users a used to it.

It could also be solved by adding a seperate toggle command.

I think text alignment it is the same. Also it is the same for headlines (the dropdown in the playground). If you select the same style again, it should be reverted.

etrepum commented 6 days ago

You could certainly do this on your own by registering the command at a higher priority, detecting if the selection is on a list, and then removing the list. Since lists can be nested I think either approach is probably valid, and it would be harder to override the toggle logic if that was the default.

BennyAlex commented 6 days ago

One suggestion was just adding a toggle command so its there out of the box.

I cant create a nested list inside the playground and also not in word using the keyboard shortcut so I think having the same behaviour would be the best.

Headlins cannot be nested at all so that should definitely toggle the mode.

etrepum commented 6 days ago

Looks like you're right that the command does not allow you to create nested lists, but the implementation does allow it and that's how multiple levels work. For example if you look at this document you can see several list nodes nested in listitem nodes

BennyAlex commented 1 day ago

Yes I dont say the are wrong or should not be possbile but using a keyboard short cut or the command should toggle the current list I guess