From 99624e5229fe065e4e0d3e377e0c63c994de37a6 Mon Sep 17 00:00:00 2001 From: xiange Date: Tue, 20 Feb 2024 21:05:53 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20Selection=20prohibited=20?= =?UTF-8?q?when=20non-select=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/chili-ui/src/project/tree/tree.ts | 12 ++++++++---- packages/chili/src/selection.ts | 7 ++++--- packages/chili/src/services/editorService.ts | 1 - 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/chili-ui/src/project/tree/tree.ts b/packages/chili-ui/src/project/tree/tree.ts index 91093d77..9ef8e28d 100644 --- a/packages/chili-ui/src/project/tree/tree.ts +++ b/packages/chili-ui/src/project/tree/tree.ts @@ -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; } @@ -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); diff --git a/packages/chili/src/selection.ts b/packages/chili/src/selection.ts index 01d2d8b3..ad277ea9 100644 --- a/packages/chili/src/selection.ts +++ b/packages/chili/src/selection.ts @@ -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); } @@ -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) { @@ -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(); } } diff --git a/packages/chili/src/services/editorService.ts b/packages/chili/src/services/editorService.ts index 817203da..497fbaf0 100644 --- a/packages/chili/src/services/editorService.ts +++ b/packages/chili/src/services/editorService.ts @@ -40,7 +40,6 @@ export class EditorService implements IService { } else { document.visual.resetEventHandler(); } - document.visual.viewer.update(); }; private getEventHandler(