{ "version": 3, "sources": ["../../../../src/lib/tools/selection-logic/selectOnCanvasPointerUp.ts"], "sourcesContent": ["import { Editor, HIT_TEST_MARGIN, TLShape, isShapeId } from '@tldraw/editor'\n\nexport function selectOnCanvasPointerUp(editor: Editor) {\n\tconst { selectedShapeIds } = editor\n\tconst { shiftKey, altKey, currentPagePoint } = editor.inputs\n\n\tconst hitShape = editor.getShapeAtPoint(currentPagePoint, {\n\t\thitInside: false,\n\t\tmargin: HIT_TEST_MARGIN / editor.zoomLevel,\n\t\thitLabels: true,\n\t\trenderingOnly: true,\n\t\tfilter: (shape) => !shape.isLocked,\n\t})\n\n\t// Note at the start: if we select a shape that is inside of a group,\n\t// the editor will automatically adjust the selection to the outermost\n\t// selectable shape (the group)\n\n\t// If the shape's outermost selected id (e.g. the group that contains\n\t// the shape) is not the same as the editor's only selected shape, then\n\t// we want to select the outermost selected shape instead of the shape\n\n\tif (hitShape) {\n\t\tconst outermostSelectableShape = editor.getOutermostSelectableShape(hitShape)\n\t\t// If the user is holding shift, they're either adding to or removing from\n\t\t// their selection.\n\t\tif (shiftKey && !altKey) {\n\t\t\teditor.cancelDoubleClick() // fuckin eh\n\n\t\t\tif (selectedShapeIds.includes(outermostSelectableShape.id)) {\n\t\t\t\t// Remove it from selected shapes\n\t\t\t\teditor.mark('deselecting shape')\n\t\t\t\teditor.deselect(outermostSelectableShape)\n\t\t\t} else {\n\t\t\t\t// Add it to selected shapes\n\t\t\t\teditor.mark('shift selecting shape')\n\t\t\t\teditor.setSelectedShapes([...selectedShapeIds, outermostSelectableShape.id])\n\t\t\t}\n\t\t} else {\n\t\t\tlet shapeToSelect: TLShape | undefined = undefined\n\n\t\t\tif (outermostSelectableShape === hitShape) {\n\t\t\t\t// There's no group around the shape, so we can select it.\n\t\t\t\tshapeToSelect = hitShape\n\t\t\t} else {\n\t\t\t\t// There's a group around the hit shape.\n\t\t\t\t// If the group is the current focus layer, OR if the group is\n\t\t\t\t// already selected, then we can select the shape inside the group.\n\t\t\t\t// Otherwise, if the group isn't selected and isn't our current\n\t\t\t\t// focus layer, then we need to select the group instead.\n\t\t\t\tif (\n\t\t\t\t\toutermostSelectableShape.id === editor.focusedGroupId ||\n\t\t\t\t\tselectedShapeIds.includes(outermostSelectableShape.id)\n\t\t\t\t) {\n\t\t\t\t\tshapeToSelect = hitShape\n\t\t\t\t} else {\n\t\t\t\t\tshapeToSelect = outermostSelectableShape\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (shapeToSelect && !selectedShapeIds.includes(shapeToSelect.id)) {\n\t\t\t\teditor.mark('selecting shape')\n\t\t\t\teditor.select(shapeToSelect.id)\n\t\t\t}\n\t\t}\n\t} else {\n\t\t// We didn't hit anything...\n\t\tif (shiftKey) {\n\t\t\t// If we were holding shift, then it's a noop. We keep the\n\t\t\t// current selection because we didn't add anything to it\n\t\t\treturn\n\t\t} else {\n\t\t\t// Otherwise, we clear the selction because the user selected\n\t\t\t// nothing instead of their current selection.\n\n\t\t\tif (selectedShapeIds.length > 0) {\n\t\t\t\teditor.mark('selecting none')\n\t\t\t\teditor.selectNone()\n\t\t\t}\n\n\t\t\t// If the click was inside of the current focused group, then\n\t\t\t// we keep that focused group; otherwise we clear the focused\n\t\t\t// group (reset it to the page)\n\t\t\tconst { focusedGroupId } = editor\n\n\t\t\tif (isShapeId(focusedGroupId)) {\n\t\t\t\tconst groupShape = editor.getShape(focusedGroupId)!\n\t\t\t\tif (!editor.isPointInShape(groupShape, currentPagePoint, { margin: 0, hitInside: true })) {\n\t\t\t\t\teditor.setFocusedGroup(null)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"], "mappings": "AAAA,SAAiB,iBAA0B,iBAAiB;AAErD,SAAS,wBAAwB,QAAgB;AACvD,QAAM,EAAE,iBAAiB,IAAI;AAC7B,QAAM,EAAE,UAAU,QAAQ,iBAAiB,IAAI,OAAO;AAEtD,QAAM,WAAW,OAAO,gBAAgB,kBAAkB;AAAA,IACzD,WAAW;AAAA,IACX,QA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