fix: issue with skipping tiles while dragging nodes

This commit is contained in:
Mark Mankarious
2023-08-16 16:18:43 +01:00
parent 6bf17402b3
commit 15bb5fb6d0

View File

@@ -1,5 +1,4 @@
import { produce } from 'immer';
import { CoordsUtils } from 'src/utils';
import { InteractionReducer } from 'src/types';
export const DragItems: InteractionReducer = {
@@ -11,31 +10,27 @@ export const DragItems: InteractionReducer = {
draftState.rendererRef.style.userSelect = 'auto';
},
mousemove: (draftState) => {
if (draftState.mode.type !== 'DRAG_ITEMS') return;
if (draftState.mode.type !== 'DRAG_ITEMS' || !draftState.mouse.mousedown)
return;
if (
draftState.mouse.delta !== null &&
!CoordsUtils.isEqual(draftState.mouse.delta.tile, CoordsUtils.zero())
) {
// User has moved tile since the last mouse event
const newScene = draftState.mode.items.reduce((acc, node) => {
return produce(acc, (draft) => {
const afterNodeUpdates = draftState.sceneActions.updateNode(
node.id,
{
position: draftState.mouse.position.tile
},
acc
);
// User is dragging
const newScene = draftState.mode.items.reduce((acc, node) => {
return produce(acc, (draft) => {
const afterNodeUpdates = draftState.sceneActions.updateNode(
node.id,
{
position: draftState.mouse.position.tile
},
acc
);
draft.nodes = afterNodeUpdates.nodes;
draft.connectors = afterNodeUpdates.connectors;
});
}, draftState.scene);
draft.nodes = afterNodeUpdates.nodes;
draft.connectors = afterNodeUpdates.connectors;
});
}, draftState.scene);
draftState.scene = newScene;
draftState.contextMenu = null;
}
draftState.scene = newScene;
draftState.contextMenu = null;
},
mouseup: (draftState) => {
draftState.mode = { type: 'CURSOR', showCursor: true, mousedown: null };