(options: InteractionInitOptions)
| 8 | private clickHandler?: ClickHandler; |
| 9 | |
| 10 | init(options: InteractionInitOptions) { |
| 11 | super.init(options); |
| 12 | const { editor, interaction } = this; |
| 13 | |
| 14 | this.clickHandler = new ClickHandler(editor.getDocument(), { delay: 0 }); |
| 15 | |
| 16 | const handleSelect = (event: MouseEvent) => { |
| 17 | if (!interaction.isActive()) return; |
| 18 | interaction.executeExclusiveInteraction(this, async () => { |
| 19 | const target = getEventTarget(event.target as SVGElement); |
| 20 | if (isEditingText(target)) return; |
| 21 | |
| 22 | if (this.shiftKey) { |
| 23 | // 多选 |
| 24 | if (target) { |
| 25 | if (interaction.isSelected(target)) { |
| 26 | interaction.select([target], 'remove'); |
| 27 | } else { |
| 28 | interaction.select([target], 'add'); |
| 29 | } |
| 30 | } |
| 31 | } else { |
| 32 | // 单选 |
| 33 | if (target) interaction.select([target], 'replace'); |
| 34 | else interaction.clearSelection(); |
| 35 | } |
| 36 | }); |
| 37 | }; |
| 38 | |
| 39 | this.clickHandler.onClick(handleSelect); |
| 40 | |
| 41 | document.addEventListener('keydown', this.onShiftKeyDown); |
| 42 | document.addEventListener('keyup', this.onShiftKeyUp); |
| 43 | document.addEventListener('keydown', this.onEscKeyDown); |
| 44 | } |
| 45 | |
| 46 | destroy() { |
| 47 | this.clickHandler?.destroy(); |
nothing calls this directly
no test coverage detected