Merge pull request #289 from toeverything/fix/autofocus-board-editor

fix: autofocus when create group in board
This commit is contained in:
zuomeng wang 2022-08-18 16:57:33 +08:00 committed by GitHub
commit d9c123a9b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 { MouseEvent, 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]);
const onMouseDown = useCallback(
(e: MouseEvent) => {
if (e.detail === 2) {
@ -159,6 +173,7 @@ export class EditorUtil extends TDShapeUtil<T, E> {
rootBlockId={rootBlockId}
scrollBlank={false}
isEdgeless
ref={editorRef}
/>
{editingText ? null : <Mask />}
</Container>