Skip to content

Commit

Permalink
🐞 fix: Selection prohibited when non-select command
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangechen committed Feb 20, 2024
1 parent dd90848 commit 99624e5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
12 changes: 8 additions & 4 deletions packages/chili-ui/src/project/tree/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,7 @@ export class Tree extends Control {
}

private onClick = (event: MouseEvent) => {
if (
this.document.visual.eventHandler instanceof SelectionHandler &&
this.document.visual.eventHandler.shapeType !== ShapeType.Shape
) {
if (!this.canSelect()) {
return;
}

Expand Down Expand Up @@ -178,6 +175,13 @@ export class Tree extends Control {
event.dataTransfer!.dropEffect = "move";
};

private canSelect() {
return (
this.document.visual.eventHandler instanceof SelectionHandler &&
this.document.visual.eventHandler.shapeType === ShapeType.Shape
);
}

private setLastClickItem(item: INode | undefined) {
if (this.lastClicked !== undefined) {
this.nodeMap.get(this.lastClicked)?.removeSelectedStyle(style.current);
Expand Down
7 changes: 4 additions & 3 deletions packages/chili/src/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ export class Selection implements ISelection, IDisposable {
this.removeSelectedPublish(this._selectedNodes, true);
}

private publishSelection() {
private updateSelection() {
this.document.visual.viewer.update();
PubSub.default.pub("selectionChanged", this.document, this._selectedNodes, this._unselectedNodes);
}

Expand All @@ -135,7 +136,7 @@ export class Selection implements ISelection, IDisposable {
}
});
this._selectedNodes.push(...nodes);
if (publish) this.publishSelection();
if (publish) this.updateSelection();
}

private removeSelectedPublish(nodes: INode[], publish: boolean) {
Expand All @@ -148,6 +149,6 @@ export class Selection implements ISelection, IDisposable {
}
this._selectedNodes = this._selectedNodes.filter((m) => !nodes.includes(m));
this._unselectedNodes = nodes;
if (publish) this.publishSelection();
if (publish) this.updateSelection();
}
}
1 change: 0 additions & 1 deletion packages/chili/src/services/editorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export class EditorService implements IService {
} else {
document.visual.resetEventHandler();
}
document.visual.viewer.update();
};

private getEventHandler(
Expand Down

0 comments on commit 99624e5

Please sign in to comment.