diff --git a/.changeset/soft-dots-train.md b/.changeset/soft-dots-train.md new file mode 100644 index 0000000000..a3ac42e922 --- /dev/null +++ b/.changeset/soft-dots-train.md @@ -0,0 +1,5 @@ +--- +'@udecode/plate-selection': patch +--- + +Fix enter can't unselect. diff --git a/packages/selection/src/react/BlockSelectionPlugin.tsx b/packages/selection/src/react/BlockSelectionPlugin.tsx index 6415e8b1bc..c57fb71a8c 100644 --- a/packages/selection/src/react/BlockSelectionPlugin.tsx +++ b/packages/selection/src/react/BlockSelectionPlugin.tsx @@ -258,6 +258,22 @@ export const BlockSelectionAfterEditable: EditableSiblingComponent = () => { export const BlockSelectionPlugin = createTPlatePlugin({ key: 'blockSelection', + extendEditor: ({ api, editor, getOptions }) => { + const { setSelection } = editor; + + editor.setSelection = (...args) => { + if ( + getOptions().selectedIds!.size > 0 && + !editor.getOption(BlockMenuPlugin, 'openId') + ) { + api.blockSelection.unselect(); + } + + setSelection(...args); + }; + + return editor; + }, options: { areaOptions: { behaviour: { @@ -301,9 +317,6 @@ export const BlockSelectionPlugin = createTPlatePlugin({ const target = event.target as HTMLElement; if (target.dataset.platePreventUnselect) return; - - console.log(editor.getOption(BlockMenuPlugin, 'openId'), 'fj'); - if ( event.button === 0 && getOptions().selectedIds!.size > 0 &&