From db77a7f3d3c28665c756bf0e5913fb2717e654b5 Mon Sep 17 00:00:00 2001 From: tzhangchi Date: Thu, 8 Sep 2022 13:20:45 +0800 Subject: [PATCH 1/3] 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; } From 04065bd6bd6f1445a95c56ad686df5f4ff37098b Mon Sep 17 00:00:00 2001 From: tzhangchi Date: Thu, 8 Sep 2022 13:57:53 +0800 Subject: [PATCH 2/3] feat(code): focus --- .../editor-blocks/src/blocks/code/CodeView.tsx | 11 ++++++----- .../editor-plugins/src/menu/command-menu/Menu.tsx | 8 +++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/libs/components/editor-blocks/src/blocks/code/CodeView.tsx b/libs/components/editor-blocks/src/blocks/code/CodeView.tsx index 86845789c5..ff6638deb3 100644 --- a/libs/components/editor-blocks/src/blocks/code/CodeView.tsx +++ b/libs/components/editor-blocks/src/blocks/code/CodeView.tsx @@ -39,7 +39,7 @@ import { yaml } from '@codemirror/legacy-modes/mode/yaml'; import { Extension } from '@codemirror/state'; import { BlockPendantProvider, - useOnSelect, + useOnSelectActive, } from '@toeverything/components/editor-core'; import { DuplicateIcon } from '@toeverything/components/icons'; import { Option, Select, styled } from '@toeverything/components/ui'; @@ -147,7 +147,8 @@ export const CodeView = ({ block, editor }: CreateCodeView) => { codeMirror?.current?.view?.focus(); } }; - useOnSelect(block.id, (_is_select: boolean) => { + //TODO listen codeMirror.up down event , active + useOnSelectActive(block.id, () => { focusCode(); }); const onChange = (value: string) => { @@ -161,9 +162,9 @@ export const CodeView = ({ block, editor }: CreateCodeView) => { }; useEffect(() => { handleLangChange(langType ? langType : DEFAULT_LANG); - setTimeout(() => { - focusCode(); - }, 100); + // setTimeout(() => { + // focusCode(); + // }, 100); }, []); const copyCode = () => { diff --git a/libs/components/editor-plugins/src/menu/command-menu/Menu.tsx b/libs/components/editor-plugins/src/menu/command-menu/Menu.tsx index 2772ec0d41..1bdda4e739 100644 --- a/libs/components/editor-plugins/src/menu/command-menu/Menu.tsx +++ b/libs/components/editor-plugins/src/menu/command-menu/Menu.tsx @@ -118,7 +118,7 @@ export const CommandMenu = ({ editor, hooks, style }: CommandMenuProps) => { ?.getRangeAt(0) ?.getBoundingClientRect(); if (rect) { - let rectTop = rect.top; + const rectTop = rect.top; const clientHeight = document.documentElement.clientHeight; @@ -224,8 +224,10 @@ export const CommandMenu = ({ editor, hooks, style }: CommandMenuProps) => { await commonCommandMenuHandler(blockId, type, editor); } const block = await editor.getBlockById(blockId); - let nextBlock = await block.nextSibling(); - editor.selectionManager.activeNodeByNodeId(nextBlock.id); + const nextBlock = await block.nextSibling(); + setTimeout(() => { + editor.selectionManager.activeNodeByNodeId(nextBlock.id); + }); if (block.blockProvider.isEmpty()) { block.remove(); } From 917b4b64f4f80f1ed2b22888addc8e83170f8f98 Mon Sep 17 00:00:00 2001 From: tzhangchi Date: Thu, 8 Sep 2022 14:10:03 +0800 Subject: [PATCH 3/3] fix(code):better experience --- libs/components/editor-blocks/src/blocks/code/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/components/editor-blocks/src/blocks/code/index.ts b/libs/components/editor-blocks/src/blocks/code/index.ts index 4239add745..e7d06cb00a 100644 --- a/libs/components/editor-blocks/src/blocks/code/index.ts +++ b/libs/components/editor-blocks/src/blocks/code/index.ts @@ -1,21 +1,21 @@ +import { Protocol } from '@toeverything/datasource/db-service'; import { - BaseView, AsyncBlock, + BaseView, BlockEditor, HTML2BlockResult, } from '@toeverything/framework/virgo'; -import { Protocol } from '@toeverything/datasource/db-service'; -import { CodeView } from './CodeView'; import { Block2HtmlProps, commonBlock2HtmlContent, commonHTML2block, } from '../../utils/commonBlockClip'; +import { CodeView } from './CodeView'; export class CodeBlock extends BaseView { type = Protocol.Block.Type.code; public override selectable = true; - public override editable = false; + public override editable = true; // View = CodeView; View = CodeView; override async onCreate(block: AsyncBlock): Promise {