Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix: autofocus when create group in board

alt041bb7368ffe7
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<T, E> {
Component = TDShapeUtil.Component<T, E, TDMeta>(
({ shape, meta: { app }, events, isEditing, onShapeChange }, ref) => {
const containerRef = useRef<HTMLDivElement>();
+ const editorRef = useRef<BlockEditor>();
const {
workspace,
rootBlockId,
@@ -135,6 +137,18 @@ export class EditorUtil extends TDShapeUtil<T, E> {
}
}, [app, state, shape.id, editingText, editingId]);
+ useEffect(() => {
+ (async () => {
+ if (isEditing) {
+ const lastBlock =
+ await editorRef.current.getLastBlock();
+ editorRef.current.selectionManager.activeNodeByNodeId(
+ lastBlock.id
+ );
+ }
+ })();
+ }, [isEditing]);
+
return (
<HTMLContainer ref={ref} {...events}>
<Container
@@ -149,6 +163,7 @@ export class EditorUtil extends TDShapeUtil<T, E> {
rootBlockId={rootBlockId}
scrollBlank={false}
isEdgeless
+ ref={editorRef}
/>
{editingText ? null : <Mask />}
</Container>