diff --git a/packages/core/src/effects/useSelectionEffect.ts b/packages/core/src/effects/useSelectionEffect.ts index bb0bbd372..2a5c5b60b 100644 --- a/packages/core/src/effects/useSelectionEffect.ts +++ b/packages/core/src/effects/useSelectionEffect.ts @@ -61,10 +61,10 @@ export const useSelectionEffect = (engine: Engine) => { if (operation.focusNode !== node) { operation.focusClean() } - selection.select(node) + selection.select(node, true) } } else { - selection.select(tree) + selection.select(tree, true) } }) } diff --git a/packages/core/src/events/mutation/AbstractMutationNodeEvent.ts b/packages/core/src/events/mutation/AbstractMutationNodeEvent.ts index 00eb0f45b..136220a7f 100644 --- a/packages/core/src/events/mutation/AbstractMutationNodeEvent.ts +++ b/packages/core/src/events/mutation/AbstractMutationNodeEvent.ts @@ -8,6 +8,8 @@ export interface IMutationNodeEventData { target: TreeNode | TreeNode[] // 事件发生的来源对象 originSourceParents?: TreeNode | TreeNode[] + //扩展数据 + extra?: any } export class AbstractMutationNodeEvent { diff --git a/packages/core/src/models/Selection.ts b/packages/core/src/models/Selection.ts index a0b4fec0c..d073d24b3 100644 --- a/packages/core/src/models/Selection.ts +++ b/packages/core/src/models/Selection.ts @@ -35,20 +35,23 @@ export class Selection { }) } - trigger(type = SelectNodeEvent) { + trigger(type = SelectNodeEvent, fromUser = false) { return this.operation.dispatch( new type({ target: this.operation.tree, source: this.operation.getSelectedNodes(), + extra: { + fromUser, + }, }) ) } - select(id: string | TreeNode) { + select(id: string | TreeNode, fromUser?: boolean) { if (isStr(id)) { if (this.selected.length === 1 && this.selected.includes(id)) return this.selected = [id] - this.trigger() + this.trigger(SelectNodeEvent, fromUser) } else { this.select(id?.id) }