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

Add right click to delete points in desktop mask/zone editor #12744

Merged
merged 1 commit into from
Aug 9, 2024
Merged
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
26 changes: 26 additions & 0 deletions web/src/components/settings/PolygonCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,29 @@ export function PolygonCanvas({
const mousePos = stage.getPointerPosition() ?? { x: 0, y: 0 };
const intersection = stage.getIntersection(mousePos);

// right click on desktops to delete a point
if (
e.evt instanceof MouseEvent &&
e.evt.button === 2 &&
intersection?.getClassName() == "Circle"
) {
const pointIndex = parseInt(intersection.name()?.split("-")[1]);
if (!isNaN(pointIndex)) {
const updatedPoints = activePolygon.points.filter(
(_, index) => index !== pointIndex,
);
updatedPolygons[activePolygonIndex] = {
...activePolygon,
points: updatedPoints,
pointsOrder: activePolygon.pointsOrder?.filter(
(_, index) => index !== pointIndex,
),
};
setPolygons(updatedPolygons);
}
return;
}

if (
activePolygon.points.length >= 3 &&
intersection?.getClassName() == "Circle" &&
Expand Down Expand Up @@ -236,6 +259,9 @@ export function PolygonCanvas({
onMouseDown={handleMouseDown}
onTouchStart={handleMouseDown}
onMouseOver={handleStageMouseOver}
onContextMenu={(e) => {
e.evt.preventDefault();
}}
>
<Layer>
<Image
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/settings/PolygonEditControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default function PolygonEditControls({
<MdUndo className="text-secondary-foreground" />
</Button>
</TooltipTrigger>
<TooltipContent>Undo</TooltipContent>
<TooltipContent>Remove last point</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger asChild>
Expand Down