mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-12-12 10:45:54 +00:00
fix(map): prevent deselect on click to map (#96)
Fixes #80 - Prevents single node deselection on background / same node click - Allows deseletion of all nodes if multiple are currently selected
This commit is contained in:
@@ -119,7 +119,7 @@ const MapComp = ({
|
|||||||
isSoftBackground,
|
isSoftBackground,
|
||||||
onAddSystem,
|
onAddSystem,
|
||||||
}: MapCompProps) => {
|
}: MapCompProps) => {
|
||||||
const { getNode } = useReactFlow();
|
const { getNode, getNodes } = useReactFlow();
|
||||||
const [nodes, , onNodesChange] = useNodesState<Node<SolarSystemRawType>>(initialNodes);
|
const [nodes, , onNodesChange] = useNodesState<Node<SolarSystemRawType>>(initialNodes);
|
||||||
const [edges, , onEdgesChange] = useEdgesState<Edge<SolarSystemConnection>>(initialEdges);
|
const [edges, , onEdgesChange] = useEdgesState<Edge<SolarSystemConnection>>(initialEdges);
|
||||||
|
|
||||||
@@ -186,6 +186,12 @@ const MapComp = ({
|
|||||||
(changes: NodeChange[]) => {
|
(changes: NodeChange[]) => {
|
||||||
const systemsIdsToRemove: string[] = [];
|
const systemsIdsToRemove: string[] = [];
|
||||||
|
|
||||||
|
// prevents single node deselection on background / same node click
|
||||||
|
// allows deseletion of all nodes if multiple are currently selected
|
||||||
|
if (changes.length === 1 && changes[0].type == 'select' && changes[0].selected === false) {
|
||||||
|
changes[0].selected = getNodes().filter(node => node.selected).length === 1;
|
||||||
|
}
|
||||||
|
|
||||||
const nextChanges = changes.reduce((acc, change) => {
|
const nextChanges = changes.reduce((acc, change) => {
|
||||||
if (change.type !== 'remove') {
|
if (change.type !== 'remove') {
|
||||||
return [...acc, change];
|
return [...acc, change];
|
||||||
|
|||||||
Reference in New Issue
Block a user