Skip to content

Commit

Permalink
fix(mind): the mind element can not selected issue after press plus icon
Browse files Browse the repository at this point in the history
  • Loading branch information
pubuzhixing8 committed Aug 8, 2024
1 parent b492680 commit 11804a7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/violet-otters-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@plait/mind': patch
---

fix the mind element can not selected issue after press plus icon
13 changes: 8 additions & 5 deletions packages/mind/src/generators/node-plus.generator.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -113,11 +113,14 @@ export class NodePlusGenerator extends Generator<MindElement> implements AfterDr
.subscribe(e => {
e.preventDefault();
});
fromEvent(this.g, 'pointerup')
fromEvent<PointerEvent>(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);
});
}
}
4 changes: 1 addition & 3 deletions packages/mind/src/utils/mind.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 11804a7

Please sign in to comment.