Skip to content

Commit

Permalink
refactor(behaviors): optimize drag-element behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Aarebecca committed Dec 12, 2024
1 parent ff09189 commit fd5802b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/g6/src/behaviors/drag-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,18 @@ export class DragElement extends BaseBehavior<DragElementOptions> {
this.enable = this.validate(event);
if (!this.enable) return;

const { batch, canvas } = this.context;
const { batch, canvas, graph } = this.context;
canvas.setCursor(this.options!.cursor?.grabbing || 'grabbing');
this.isDragging = true;
batch!.startBatch();
this.target = this.getSelectedNodeIDs([event.target.id]);

// 如果当前节点是选中状态,则查询出画布中所有选中的节点,否则只拖拽当前节点
// If the current node is selected, query all selected nodes in the canvas, otherwise only drag the current node
const id = event.target.id;
const states = graph.getElementState(id);
if (states.includes(this.options.state)) this.target = this.getSelectedNodeIDs([id]);
else this.target = [id];

this.hideEdge();
this.context.graph.frontElement(this.target);
if (this.options.shadow) this.createShadow(this.target);
Expand Down

0 comments on commit fd5802b

Please sign in to comment.