From 42209f419e98b48c27a6131c4727cff6fe7c9144 Mon Sep 17 00:00:00 2001 From: Croc-ye <1402322262@qq.com> Date: Tue, 24 Dec 2024 19:33:27 +0800 Subject: [PATCH 1/7] fix: fix the exception of inputting Chinese when selecting multiple cells --- packages/table/src/react/onKeyDownTable.ts | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/table/src/react/onKeyDownTable.ts b/packages/table/src/react/onKeyDownTable.ts index 9489f504b5..fcbafb45d1 100644 --- a/packages/table/src/react/onKeyDownTable.ts +++ b/packages/table/src/react/onKeyDownTable.ts @@ -1,10 +1,14 @@ +import { TableRowPlugin } from '@udecode/plate/react'; import { type TElement, + collapseSelection, getAboveNode, + isExpanded, isHotkey, select, } from '@udecode/plate-common'; import { type KeyboardHandler, Hotkeys } from '@udecode/plate-common/react'; +import { type BaseEditor, Editor } from 'slate'; import { type TableConfig, @@ -22,6 +26,30 @@ export const onKeyDownTable: KeyboardHandler = ({ }) => { if (event.defaultPrevented) return; + const compositeKeyCode = 229; + + if ( + event.which === compositeKeyCode && + editor.selection && + isExpanded(editor.selection) + ) { + // fix the exception of inputting Chinese when selecting multiple cells + const trElements = Array.from( + Editor.nodes(editor as BaseEditor, { + at: editor.selection, + match: (n) => n.type === TableRowPlugin.key, + }) + ); + + if (trElements.length > 0) { + collapseSelection(editor, { + edge: 'end', + }); + + return; + } + } + const isKeyDown: any = { 'shift+down': isHotkey('shift+down', event), 'shift+left': isHotkey('shift+left', event), From 87d4fe0282a55cb97e0a717aeabb5dc47fa63ff0 Mon Sep 17 00:00:00 2001 From: Croc-ye <1402322262@qq.com> Date: Tue, 24 Dec 2024 19:44:51 +0800 Subject: [PATCH 2/7] feat: updates --- packages/table/src/react/onKeyDownTable.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/table/src/react/onKeyDownTable.ts b/packages/table/src/react/onKeyDownTable.ts index fcbafb45d1..79417a6075 100644 --- a/packages/table/src/react/onKeyDownTable.ts +++ b/packages/table/src/react/onKeyDownTable.ts @@ -37,11 +37,12 @@ export const onKeyDownTable: KeyboardHandler = ({ const trElements = Array.from( Editor.nodes(editor as BaseEditor, { at: editor.selection, + // @ts-ignore match: (n) => n.type === TableRowPlugin.key, }) ); - if (trElements.length > 0) { + if (trElements.length > 1) { collapseSelection(editor, { edge: 'end', }); From 8609afb0582a76e580a2b50f91a5e291d06e4da1 Mon Sep 17 00:00:00 2001 From: Croc-ye <1402322262@qq.com> Date: Tue, 24 Dec 2024 20:12:43 +0800 Subject: [PATCH 3/7] feat: update --- packages/table/src/react/onKeyDownTable.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/table/src/react/onKeyDownTable.ts b/packages/table/src/react/onKeyDownTable.ts index 79417a6075..2044a22442 100644 --- a/packages/table/src/react/onKeyDownTable.ts +++ b/packages/table/src/react/onKeyDownTable.ts @@ -3,12 +3,12 @@ import { type TElement, collapseSelection, getAboveNode, + getNodeEntries, isExpanded, isHotkey, select, } from '@udecode/plate-common'; import { type KeyboardHandler, Hotkeys } from '@udecode/plate-common/react'; -import { type BaseEditor, Editor } from 'slate'; import { type TableConfig, @@ -35,10 +35,9 @@ export const onKeyDownTable: KeyboardHandler = ({ ) { // fix the exception of inputting Chinese when selecting multiple cells const trElements = Array.from( - Editor.nodes(editor as BaseEditor, { + getNodeEntries(editor, { at: editor.selection, - // @ts-ignore - match: (n) => n.type === TableRowPlugin.key, + match: { type: TableRowPlugin.key }, }) ); From 406ae3d3f3b1db3d3426b8e1c81caadd9cad47a2 Mon Sep 17 00:00:00 2001 From: Croc-ye <1402322262@qq.com> Date: Tue, 24 Dec 2024 20:44:02 +0800 Subject: [PATCH 4/7] feat: update --- packages/table/src/react/onKeyDownTable.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/table/src/react/onKeyDownTable.ts b/packages/table/src/react/onKeyDownTable.ts index 2044a22442..8557768549 100644 --- a/packages/table/src/react/onKeyDownTable.ts +++ b/packages/table/src/react/onKeyDownTable.ts @@ -1,4 +1,4 @@ -import { TableRowPlugin } from '@udecode/plate/react'; +import { TableCellPlugin } from '@udecode/plate/react'; import { type TElement, collapseSelection, @@ -29,19 +29,20 @@ export const onKeyDownTable: KeyboardHandler = ({ 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 trElements = Array.from( + const tdEntries = Array.from( getNodeEntries(editor, { at: editor.selection, - match: { type: TableRowPlugin.key }, + match: { type: TableCellPlugin.key }, }) ); - if (trElements.length > 1) { + if (tdEntries.length > 1) { collapseSelection(editor, { edge: 'end', }); From 07460a565eef131992d112b83db12e246615c84a Mon Sep 17 00:00:00 2001 From: Croc-ye <1402322262@qq.com> Date: Tue, 24 Dec 2024 21:10:28 +0800 Subject: [PATCH 5/7] feat: update --- packages/table/src/react/onKeyDownTable.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/table/src/react/onKeyDownTable.ts b/packages/table/src/react/onKeyDownTable.ts index 8557768549..5d3911a27c 100644 --- a/packages/table/src/react/onKeyDownTable.ts +++ b/packages/table/src/react/onKeyDownTable.ts @@ -13,6 +13,7 @@ import { type KeyboardHandler, Hotkeys } from '@udecode/plate-common/react'; import { type TableConfig, KEY_SHIFT_EDGES, + getCellTypes, getNextTableCell, getPreviousTableCell, getTableEntries, @@ -38,7 +39,7 @@ export const onKeyDownTable: KeyboardHandler = ({ const tdEntries = Array.from( getNodeEntries(editor, { at: editor.selection, - match: { type: TableCellPlugin.key }, + match: { type: getCellTypes(editor) }, }) ); From 8bb9bac211add234d067df2316e37c01b14f7234 Mon Sep 17 00:00:00 2001 From: Croc-ye <1402322262@qq.com> Date: Tue, 24 Dec 2024 21:11:49 +0800 Subject: [PATCH 6/7] feat: update --- packages/table/src/react/onKeyDownTable.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/table/src/react/onKeyDownTable.ts b/packages/table/src/react/onKeyDownTable.ts index 5d3911a27c..0d70014c20 100644 --- a/packages/table/src/react/onKeyDownTable.ts +++ b/packages/table/src/react/onKeyDownTable.ts @@ -1,4 +1,3 @@ -import { TableCellPlugin } from '@udecode/plate/react'; import { type TElement, collapseSelection, From 0c6c031a243b3ebaa12ef3f171299b513002fb91 Mon Sep 17 00:00:00 2001 From: Ziad Beyens Date: Tue, 24 Dec 2024 16:55:49 +0100 Subject: [PATCH 7/7] Create young-files-allow.md --- .changeset/young-files-allow.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/young-files-allow.md 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