diff --git a/.changeset/young-files-allow.md b/.changeset/young-files-allow.md new file mode 100644 index 0000000000..c645c24a09 --- /dev/null +++ b/.changeset/young-files-allow.md @@ -0,0 +1,5 @@ +--- +"@udecode/plate-table": patch +--- + +fix: exception of inputting Chinese when selecting multiple cells diff --git a/packages/table/src/react/onKeyDownTable.ts b/packages/table/src/react/onKeyDownTable.ts index 9489f504b5..0d70014c20 100644 --- a/packages/table/src/react/onKeyDownTable.ts +++ b/packages/table/src/react/onKeyDownTable.ts @@ -1,6 +1,9 @@ import { type TElement, + collapseSelection, getAboveNode, + getNodeEntries, + isExpanded, isHotkey, select, } from '@udecode/plate-common'; @@ -9,6 +12,7 @@ import { type KeyboardHandler, Hotkeys } from '@udecode/plate-common/react'; import { type TableConfig, KEY_SHIFT_EDGES, + getCellTypes, getNextTableCell, getPreviousTableCell, getTableEntries, @@ -22,6 +26,31 @@ export const onKeyDownTable: KeyboardHandler = ({ }) => { if (event.defaultPrevented) return; + const compositeKeyCode = 229; + + if ( + // This exception only occurs when IME composition is triggered, and can be identified by this keycode + event.which === compositeKeyCode && + editor.selection && + isExpanded(editor.selection) + ) { + // fix the exception of inputting Chinese when selecting multiple cells + const tdEntries = Array.from( + getNodeEntries(editor, { + at: editor.selection, + match: { type: getCellTypes(editor) }, + }) + ); + + if (tdEntries.length > 1) { + collapseSelection(editor, { + edge: 'end', + }); + + return; + } + } + const isKeyDown: any = { 'shift+down': isHotkey('shift+down', event), 'shift+left': isHotkey('shift+left', event),