Skip to content

Commit fc670dc

Browse files
AntamansidAntamansid
andauthored
fix: unselect entities without meta key pressed (#42)
Co-authored-by: Antamansid <[email protected]>
1 parent 665817b commit fc670dc

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

src/components/canvas/anchors/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { frameDebouncer } from "../../../services/optimizations/frameDebouncer";
33
import { AnchorState, EAnchorType } from "../../../store/anchor/Anchor";
44
import { TBlockId } from "../../../store/block/Block";
55
import { selectBlockAnchor } from "../../../store/block/selectors";
6+
import { isMetaKeyEvent } from "../../../utils/functions";
67
import { TPoint } from "../../../utils/types/shapes";
78
import { GraphComponent } from "../GraphComponent";
89
import { GraphLayer, TGraphLayerContext } from "../layers/graphLayer/GraphLayer";
@@ -104,9 +105,22 @@ export class Anchor extends GraphComponent<TAnchorProps, TAnchorState> {
104105
event.stopPropagation();
105106

106107
switch (event.type) {
107-
case "click":
108+
case "click": {
109+
const { blocksList, connectionsList } = this.context.graph.rootStore;
110+
const isAnyBlockSelected = blocksList.$selectedBlocks.value.length !== 0;
111+
const isAnyConnectionSelected = connectionsList.$selectedConnections.value.size !== 0;
112+
113+
if (!isMetaKeyEvent(event) && isAnyBlockSelected) {
114+
blocksList.resetSelection();
115+
}
116+
117+
if (!isMetaKeyEvent(event) && isAnyConnectionSelected) {
118+
connectionsList.resetSelection();
119+
}
120+
108121
this.toggleSelected();
109122
break;
123+
}
110124
case "mouseenter": {
111125
this.setState({ raised: true });
112126
this.computeRenderSize(this.props.size, true);

src/components/canvas/blocks/controllers/BlockController.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ export class BlockController {
1919
addEventListeners(block as EventTarget, {
2020
click(event: MouseEvent) {
2121
event.stopPropagation();
22+
23+
const { connectionsList } = block.context.graph.rootStore;
24+
const isAnyConnectionSelected = connectionsList.$selectedConnections.value.size !== 0;
25+
26+
if (!isMetaKeyEvent(event) && isAnyConnectionSelected) {
27+
connectionsList.resetSelection();
28+
}
29+
2230
block.context.graph.api.selectBlocks(
2331
[block.props.id],
2432
/**

src/components/canvas/connections/BlockConnection.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,27 @@ export class BlockConnection<T extends TConnection>
189189
super.handleEvent(event);
190190

191191
switch (event.type) {
192-
case "click":
192+
case "click": {
193+
const { blocksList } = this.context.graph.rootStore;
194+
const isAnyBlockSelected = blocksList.$selectedBlocks.value.length !== 0;
195+
const isAnyAnchorSelected = Boolean(blocksList.$selectedAnchor.value);
196+
197+
if (!isMetaKeyEvent(event) && isAnyBlockSelected) {
198+
blocksList.resetSelection();
199+
}
200+
201+
if (!isMetaKeyEvent(event) && isAnyAnchorSelected) {
202+
blocksList.resetSelection();
203+
}
204+
193205
this.context.graph.api.selectConnections(
194206
[this.props.id],
195207
!isMetaKeyEvent(event) ? true : !this.state.selected,
196208
!isMetaKeyEvent(event) ? ESelectionStrategy.REPLACE : ESelectionStrategy.APPEND
197209
);
210+
198211
break;
212+
}
199213
}
200214
}
201215

0 commit comments

Comments
 (0)