From db77a7f3d3c28665c756bf0e5913fb2717e654b5 Mon Sep 17 00:00:00 2001 From: tzhangchi Date: Thu, 8 Sep 2022 13:20:45 +0800 Subject: [PATCH] feat(onBackspace): support remove group when select group --- .../editor-blocks/src/blocks/text/TextView.tsx | 17 +++++++++++++++++ .../src/components/text-manage/TextManage.tsx | 1 + 2 files changed, 18 insertions(+) diff --git a/libs/components/editor-blocks/src/blocks/text/TextView.tsx b/libs/components/editor-blocks/src/blocks/text/TextView.tsx index 402c648287..baae481c91 100644 --- a/libs/components/editor-blocks/src/blocks/text/TextView.tsx +++ b/libs/components/editor-blocks/src/blocks/text/TextView.tsx @@ -97,6 +97,23 @@ export const TextView = ({ const onBackspace: TextProps['handleBackSpace'] = editor.withBatch( async props => { const { isCollAndStart } = props; + const activeBlockIds = + editor.selectionManager.getSelectedNodesIds(); + + // when only one group selected , remove this group block + if (activeBlockIds && activeBlockIds.length === 1) { + const activeBlock = await editor.getBlockById( + activeBlockIds[0] + ); + + if ( + activeBlock && + activeBlock.type === Protocol.Block.Type.group + ) { + await activeBlock.remove(); + return true; + } + } if (!isCollAndStart) { return false; } diff --git a/libs/components/editor-blocks/src/components/text-manage/TextManage.tsx b/libs/components/editor-blocks/src/components/text-manage/TextManage.tsx index 4b32a9da43..df3ab85abb 100644 --- a/libs/components/editor-blocks/src/components/text-manage/TextManage.tsx +++ b/libs/components/editor-blocks/src/components/text-manage/TextManage.tsx @@ -406,6 +406,7 @@ export const TextManage = forwardRef( textRef.current.isEmpty() || textRef.current.isSelectAll(); const ifSelectGroup = await selectGroupBlocks(isSelectAll); + if (ifSelectGroup) { return false; }