diff --git a/.changeset/violet-otters-rule.md b/.changeset/violet-otters-rule.md new file mode 100644 index 000000000..3278b2da7 --- /dev/null +++ b/.changeset/violet-otters-rule.md @@ -0,0 +1,5 @@ +--- +'@plait/mind': patch +--- + +fix the mind element can not selected issue after press plus icon diff --git a/packages/mind/src/generators/node-plus.generator.ts b/packages/mind/src/generators/node-plus.generator.ts index 91f3a470c..a19064215 100644 --- a/packages/mind/src/generators/node-plus.generator.ts +++ b/packages/mind/src/generators/node-plus.generator.ts @@ -1,4 +1,4 @@ -import { PlaitBoard, createG } from '@plait/core'; +import { PlaitBoard, PlaitOptionsBoard, createG, temporaryDisableSelection } from '@plait/core'; import { MindElement, BaseData, PlaitMind, MindElementShape, LayoutDirection } from '../interfaces'; import { getRectangleByNode } from '../utils/position/node'; import { getShapeByElement } from '../utils/node-style/shape'; @@ -113,11 +113,14 @@ export class NodePlusGenerator extends Generator implements AfterDr .subscribe(e => { e.preventDefault(); }); - fromEvent(this.g, 'pointerup') + fromEvent(this.g, 'pointerup') .pipe(take(1)) - .subscribe(() => { - const path = findNewChildNodePath(this.board, element); - insertMindElement(this.board as PlaitMindBoard, element, path); + .subscribe((event: PointerEvent) => { + // wait the event period end of pointerup to otherwise the pointerup will cause new element lose selected state + setTimeout(() => { + const path = findNewChildNodePath(this.board, element); + insertMindElement(this.board as PlaitMindBoard, element, path); + }, 0); }); } } diff --git a/packages/mind/src/utils/mind.ts b/packages/mind/src/utils/mind.ts index f5e99e377..1c1293939 100644 --- a/packages/mind/src/utils/mind.ts +++ b/packages/mind/src/utils/mind.ts @@ -1,4 +1,4 @@ -import { addSelectedElement, clearSelectedElement, idCreator, Path, PlaitBoard, Transforms } from '@plait/core'; +import { addSelectedElement, clearSelectedElement, getSelectedElements, idCreator, Path, PlaitBoard, Transforms } from '@plait/core'; import { MindElement, PlaitMind } from '../interfaces/element'; import { editTopic } from './node/common'; import { createMindElement, INHERIT_ATTRIBUTE_KEYS, InheritAttribute } from './node/create-node'; @@ -66,9 +66,7 @@ export const insertMindElement = (board: PlaitMindBoard, inheritNode: MindElemen }); delete newNode.layout; } - const newElement = createMindElement('', TOPIC_FONT_SIZE, TEXT_DEFAULT_HEIGHT, newNode); - Transforms.insertNode(board, newElement, path); clearSelectedElement(board); addSelectedElement(board, newElement);