Skip to content

Commit

Permalink
feat(core): support fromUser for SelectionEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Oct 29, 2021
1 parent e929f61 commit d3aeda7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/effects/useSelectionEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export interface IMutationNodeEventData {
target: TreeNode | TreeNode[]
// 事件发生的来源对象
originSourceParents?: TreeNode | TreeNode[]
//扩展数据
extra?: any
}

export class AbstractMutationNodeEvent {
Expand Down
9 changes: 6 additions & 3 deletions packages/core/src/models/Selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit d3aeda7

Please sign in to comment.