UNPKG

tldraw

Version:

A tiny little drawing editor.

63 lines (62 loc) 2.29 kB
import { isShapeId } from "@tldraw/editor"; function selectOnCanvasPointerUp(editor, info) { const selectedShapeIds = editor.getSelectedShapeIds(); const { currentPagePoint } = editor.inputs; const { shiftKey, altKey, accelKey } = info; const additiveSelectionKey = shiftKey || accelKey; const hitShape = editor.getShapeAtPoint(currentPagePoint, { hitInside: false, margin: editor.options.hitTestMargin / editor.getZoomLevel(), hitLabels: true, renderingOnly: true, filter: (shape) => !shape.isLocked }); if (hitShape) { const outermostSelectableShape = editor.getOutermostSelectableShape(hitShape); if (additiveSelectionKey && !altKey) { editor.cancelDoubleClick(); if (selectedShapeIds.includes(outermostSelectableShape.id)) { editor.markHistoryStoppingPoint("deselecting shape"); editor.deselect(outermostSelectableShape); } else { editor.markHistoryStoppingPoint("shift selecting shape"); editor.setSelectedShapes([...selectedShapeIds, outermostSelectableShape.id]); } } else { let shapeToSelect = void 0; if (outermostSelectableShape === hitShape) { shapeToSelect = hitShape; } else { if (outermostSelectableShape.id === editor.getFocusedGroupId() || selectedShapeIds.includes(outermostSelectableShape.id)) { shapeToSelect = hitShape; } else { shapeToSelect = outermostSelectableShape; } } if (shapeToSelect && !selectedShapeIds.includes(shapeToSelect.id)) { editor.markHistoryStoppingPoint("selecting shape"); editor.select(shapeToSelect.id); } } } else { if (additiveSelectionKey) { return; } else { if (selectedShapeIds.length > 0) { editor.markHistoryStoppingPoint("selecting none"); editor.selectNone(); } const focusedGroupId = editor.getFocusedGroupId(); if (isShapeId(focusedGroupId)) { const groupShape = editor.getShape(focusedGroupId); if (!editor.isPointInShape(groupShape, currentPagePoint, { margin: 0, hitInside: true })) { editor.setFocusedGroup(null); } } } } } export { selectOnCanvasPointerUp }; //# sourceMappingURL=selectOnCanvasPointerUp.mjs.map