From 41bb7368ffe7b8f7089962ac3179eef0495afbb9 Mon Sep 17 00:00:00 2001 From: alt0 Date: Thu, 18 Aug 2022 15:45:58 +0800 Subject: [PATCH] fix: autofocus when create group in board --- .../board-shapes/src/editor-util/EditorUtil.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libs/components/board-shapes/src/editor-util/EditorUtil.tsx b/libs/components/board-shapes/src/editor-util/EditorUtil.tsx index 6e6f123a72..0855310081 100644 --- a/libs/components/board-shapes/src/editor-util/EditorUtil.tsx +++ b/libs/components/board-shapes/src/editor-util/EditorUtil.tsx @@ -8,6 +8,7 @@ import { TDShapeType, TransformInfo, } from '@toeverything/components/board-types'; +import type { BlockEditor } from '@toeverything/components/editor-core'; import { MIN_PAGE_WIDTH } from '@toeverything/components/editor-core'; import { styled } from '@toeverything/components/ui'; import type { SyntheticEvent } from 'react'; @@ -66,6 +67,7 @@ export class EditorUtil extends TDShapeUtil { Component = TDShapeUtil.Component( ({ shape, meta: { app }, events, isEditing, onShapeChange }, ref) => { const containerRef = useRef(); + const editorRef = useRef(); const { workspace, rootBlockId, @@ -135,6 +137,18 @@ export class EditorUtil extends TDShapeUtil { } }, [app, state, shape.id, editingText, editingId]); + useEffect(() => { + (async () => { + if (isEditing) { + const lastBlock = + await editorRef.current.getLastBlock(); + editorRef.current.selectionManager.activeNodeByNodeId( + lastBlock.id + ); + } + })(); + }, [isEditing]); + return ( { rootBlockId={rootBlockId} scrollBlank={false} isEdgeless + ref={editorRef} /> {editingText ? null : }