Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#342 deselecting shape cmd+click #370

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/core/providers/canvas/use-selection.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,24 @@ export const useSelection = (
);
setSelectedShapesIds(arrayIds);
} else {
// Multiple selection, just push what is selected to the current selection
selectedShapesRefs.current = selectedShapesRefs.current.concat(
arrayIds.map(id => shapeRefs.current[id].current)
);
// Multiple selection, add or remove from current selection
const auxSelectedShapesIds = [...selectedShapesIds];
const auxSelectedShapesRefs = [...selectedShapesRefs.current];
const selectedShapeId = arrayIds[0];

// If the shape is already selected, remove it
if (auxSelectedShapesIds.includes(selectedShapeId)) {
const index = auxSelectedShapesIds.indexOf(selectedShapeId);
auxSelectedShapesIds.splice(index, 1);
auxSelectedShapesRefs.splice(index, 1);
} else {
// Else add it to the selection
auxSelectedShapesIds.push(selectedShapeId);
auxSelectedShapesRefs.push(shapeRefs.current[selectedShapeId].current);
}

setSelectedShapesIds(formerShapeIds => [...formerShapeIds, ...arrayIds]);
selectedShapesRefs.current = auxSelectedShapesRefs;
setSelectedShapesIds(auxSelectedShapesIds);
}

transformerRef?.current?.nodes(selectedShapesRefs.current);
Expand Down
8 changes: 3 additions & 5 deletions src/pods/canvas/use-multiple-selection-shape.hook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ import { SelectionInfo } from '@/core/providers/canvas/canvas.model';
import Konva from 'konva';
import { useState } from 'react';
import { SelectionRect } from './canvas.model';
import {
findFirstShapeInCoords,
getSelectedShapesFromSelectionRect,
} from './use-multiple-selection.business';
import { getSelectedShapesFromSelectionRect } from './use-multiple-selection.business';
import { getTransformerBoxAndCoords } from './transformer.utils';
import { calculateScaledCoordsFromCanvasDivCoordinatesNoScroll } from './canvas.util';
import { Stage } from 'konva/lib/Stage';
import { isUserDoingMultipleSelectionUsingCtrlOrCmdKey } from '@/common/utils/shapes';

// There's a bug here: if you make a multiple selectin and start dragging
// inside the selection but on a blank area it won't drag the selection
Expand Down Expand Up @@ -101,6 +97,7 @@ export const useMultipleSelectionShapeHook = (
return;
}

/*
const shape = findFirstShapeInCoords(shapes, mousePointerStageBasedCoord);

// If you are not dragging, but you click on a shape you should select that shape
Expand All @@ -115,6 +112,7 @@ export const useMultipleSelectionShapeHook = (
);
return;
}
*/

selectionInfo.handleClearSelection(e);
if (e.target !== e.target.getStage()) {
Expand Down
Loading