Shift+click: toggle an element in/out of multi-select
(el: HTMLElement)
| 794 | |
| 795 | /** Shift+click: toggle an element in/out of multi-select */ |
| 796 | function toggleMultiSelect(el: HTMLElement): void { |
| 797 | if (multiSelected.has(el)) { |
| 798 | // Remove from multi-select |
| 799 | multiSelected.delete(el); |
| 800 | if (multiSelected.size === 1) { |
| 801 | // Collapse back to single select |
| 802 | const [remainEl, entry] = [...multiSelected.entries()][0]; |
| 803 | multiSelected.clear(); |
| 804 | clearMultiSelection(); |
| 805 | selectedElement = remainEl; |
| 806 | currentSelection = entry.info; |
| 807 | const rect = remainEl.getBoundingClientRect(); |
| 808 | showSelectionOverlay(rect, currentSelection); |
| 809 | inspect(remainEl, currentSelection); |
| 810 | if (selectionLabel) { |
| 811 | const pathText = entry.info.filePath ? `${entry.info.filePath}:${entry.info.lineNumber}` : ""; |
| 812 | selectionLabel.innerHTML = `<span class="comp-name">${entry.info.componentName}</span>${pathText ? `<span class="comp-path">${pathText}</span>` : ""}`; |
| 813 | } |
| 814 | updateComponentDetail({ |
| 815 | tagName: entry.info.tagName, |
| 816 | componentName: entry.info.componentName, |
| 817 | filePath: entry.info.filePath, |
| 818 | lineNumber: entry.info.lineNumber, |
| 819 | }); |
| 820 | } else if (multiSelected.size === 0) { |
| 821 | clearMultiSelection(); |
| 822 | clearSelection(); |
| 823 | } else { |
| 824 | updateMultiSelectionHighlights(); |
| 825 | if (selectionLabel) { |
| 826 | selectionLabel.innerHTML = `<span class="comp-name">${multiSelected.size} elements selected</span>`; |
| 827 | } |
| 828 | } |
| 829 | return; |
| 830 | } |
| 831 | |
| 832 | // Add to multi-select |
| 833 | const resolved = resolveComponentSync(el); |
| 834 | if (!resolved) return; |
| 835 | |
| 836 | // If there's a current single selection, promote it to multi-select first |
| 837 | if (currentSelection && selectedElement && multiSelected.size === 0) { |
| 838 | multiSelected.set(selectedElement, { element: selectedElement, info: currentSelection }); |
| 839 | deselectProperty(); |
| 840 | currentSelection = null; |
| 841 | selectedElement = null; |
| 842 | setSelectionTarget(null); |
| 843 | } |
| 844 | |
| 845 | const rect = el.getBoundingClientRect(); |
| 846 | const info: ComponentInfo = { |
| 847 | tagName: resolved.tagName, |
| 848 | componentName: resolved.componentName, |
| 849 | filePath: resolved.filePath, |
| 850 | lineNumber: resolved.lineNumber, |
| 851 | columnNumber: resolved.columnNumber, |
| 852 | stack: resolved.stack, |
| 853 | boundingRect: { top: rect.top, left: rect.left, width: rect.width, height: rect.height }, |
no test coverage detected