fix(selection): handle snap grid correctly

This commit is contained in:
moklick
2020-09-11 01:39:40 +02:00
parent 7f64ffe173
commit fe3dd87d24
3 changed files with 34 additions and 50 deletions
+16
View File
@@ -25,6 +25,7 @@ import {
HandleType,
SetConnectionId,
NodePosUpdate,
NodeDiffUpdate,
FitViewParams,
TranslateExtent,
} from '../types';
@@ -101,6 +102,7 @@ export interface StoreModel {
updateNodeDimensions: Action<StoreModel, NodeDimensionUpdate>;
updateNodePos: Action<StoreModel, NodePosUpdate>;
updateNodePosDiff: Action<StoreModel, NodeDiffUpdate>;
setSelection: Action<StoreModel, boolean>;
@@ -255,6 +257,20 @@ export const storeModel: StoreModel = {
});
}),
updateNodePosDiff: action((state, { id, diff }) => {
state.elements.forEach((n) => {
if (n.id === id && isNode(n)) {
n.__rf = {
...n.__rf,
position: {
x: n.__rf.position.x + diff.x,
y: n.__rf.position.y + diff.y,
},
};
}
});
}),
setUserSelection: action((state, mousePos) => {
state.userSelectionRect = {
width: 0,