diff --git a/packages/nodes/list/src/onKeyDownList.ts b/packages/nodes/list/src/onKeyDownList.ts index d4e8bed8ab..ab3a72b4af 100644 --- a/packages/nodes/list/src/onKeyDownList.ts +++ b/packages/nodes/list/src/onKeyDownList.ts @@ -23,7 +23,6 @@ export const onKeyDownList = < if (editor.selection && (isTab || isUntab)) { const listSelected = getAboveNode(editor, { at: editor.selection, - match: { type }, }); if (listSelected) { diff --git a/packages/nodes/list/src/onkeyDownList.spec.tsx b/packages/nodes/list/src/onkeyDownList.spec.tsx new file mode 100644 index 0000000000..15f8da671b --- /dev/null +++ b/packages/nodes/list/src/onkeyDownList.spec.tsx @@ -0,0 +1,168 @@ +/** @jsx jsx */ + +import { getPlugin, HotkeyPlugin, Hotkeys } from '@udecode/plate-core'; +import { createListPlugin } from '@udecode/plate-list'; +import { jsx } from '@udecode/plate-test-utils'; +import { createPlateUIEditor } from '@udecode/plate-ui/src/utils/createPlateUIEditor'; +import * as isHotkey from 'is-hotkey'; +import { onKeyDownList } from './onKeyDownList'; + +jsx; + +it('should indent single list item', () => { + const input = ( + + + + some text + + + + + some text + + + + + ) as any; + + const output = ( + + + + some text + + + + + some text + + + + + + + ) as any; + + const event = new KeyboardEvent('keydown', { key: 'Tab' }) as any; + const editor = createPlateUIEditor({ + editor: input, + plugins: [createListPlugin()], + }); + + onKeyDownList(editor, getPlugin(editor, 'ul'))(event as any); + expect(editor.children).toEqual(output.children); +}); + +it('should indent multiple list items', () => { + const input = ( + + + + first element + + + + + second element + + + + + third element + + + + + ) as any; + + const output = ( + + + + first element + + + + + second element + + + + + third element + + + + + + + ) as any; + + const event = new KeyboardEvent('keydown', { key: 'Tab' }) as any; + const editor = createPlateUIEditor({ + editor: input, + plugins: [createListPlugin()], + }); + + onKeyDownList(editor, getPlugin(editor, 'ul'))(event as any); + expect(editor.children).toEqual(output.children); +}); + +it('should un-indent multiple list items', () => { + const input = ( + + + + first element + + + + + second element + + + + + third element + + + + + + + ) as any; + + const output = ( + + + + first element + + + + + second element + + + + + third element + + + + + ) as any; + + const event = new KeyboardEvent('keydown', { + shiftKey: true, + key: 'Tab', + }) as any; + const editor = createPlateUIEditor({ + editor: input, + plugins: [createListPlugin()], + }); + + onKeyDownList(editor, getPlugin(editor, 'ul'))(event as any); + expect(editor.children).toEqual(output.children); +});