Skip to content

Commit

Permalink
Merge pull request #3908 from Croc-ye/udecode/fix/table-mulit-cells-i…
Browse files Browse the repository at this point in the history
…nput

fix: fix the exception of inputting Chinese when selecting multiple cells
  • Loading branch information
felixfeng33 authored Dec 25, 2024
2 parents 1a1dee6 + 6db5667 commit e551e08
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/young-files-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@udecode/plate-table": patch
---

fix: exception of inputting Chinese when selecting multiple cells
29 changes: 29 additions & 0 deletions packages/table/src/react/onKeyDownTable.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {
type TElement,
collapseSelection,
getAboveNode,
getNodeEntries,
isExpanded,
isHotkey,
select,
} from '@udecode/plate-common';
Expand All @@ -9,6 +12,7 @@ import { type KeyboardHandler, Hotkeys } from '@udecode/plate-common/react';
import {
type TableConfig,
KEY_SHIFT_EDGES,
getCellTypes,
getNextTableCell,
getPreviousTableCell,
getTableEntries,
Expand All @@ -22,6 +26,31 @@ export const onKeyDownTable: KeyboardHandler<TableConfig> = ({
}) => {
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),
Expand Down

0 comments on commit e551e08

Please sign in to comment.