lexical icon indicating copy to clipboard operation
lexical copied to clipboard

Feature: Lists should be toggleable

Open BennyAlex opened this issue 1 year ago • 4 comments

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.

BennyAlex avatar Oct 15 '24 16:10 BennyAlex

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.

etrepum avatar Oct 16 '24 00:10 etrepum

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.

BennyAlex avatar Oct 16 '24 09:10 BennyAlex

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

etrepum avatar Oct 16 '24 14:10 etrepum

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

BennyAlex avatar Oct 21 '24 11:10 BennyAlex

I've investigated this issue and can confirm that list toggling is working as expected. The keyboard shortcut Cmd + Option + 5 (or Ctrl + Alt + 5 on Windows/Linux) correctly toggles numbered lists. This is implemented in the codebase and verified by test cases.

The functionality is properly implemented in:

  1. The keyboard shortcuts are defined in ShortcutsPlugin/shortcuts.ts
  2. The list toggling is handled in ShortcutsPlugin/index.tsx
  3. There are test cases in List.spec.mjs that verify the toggling behavior

The issue appears to be resolved as the current implementation does support toggling lists back to their original state.

Please let me know if I am missing anything?

kirandash avatar Apr 11 '25 14:04 kirandash

Seems fixed to me as well 👍

etrepum avatar Apr 11 '25 18:04 etrepum