From 7e640e4207d4c1260566e6074bf3d8d9c029e986 Mon Sep 17 00:00:00 2001 From: Maxim Dolgolyov Date: Wed, 3 Jun 2026 20:23:27 +0300 Subject: [PATCH] =?UTF-8?q?fix(svg-draw):=20=D1=80=D0=B5=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BE=D1=82=D0=BA=D0=BB=D1=8E=D1=87=D0=B0=D0=B5?= =?UTF-8?q?=D0=BC=20=D0=BF=D0=B5=D1=80=D0=B5=D1=82=D0=B0=D1=81=D0=BA=D0=B8?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=B0=D1=80=D1=82=D0=BE?= =?UTF-8?q?=D1=87=D0=BA=D0=B8=20=D0=BF=D1=80=D0=B8=20=D1=80=D0=B8=D1=81?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Прошлый гард не работал: dragstart срабатывает на самой карточке (draggable=true), а не на svg, поэтому e.target.closest(.svgdraw-host) был null. Теперь на pointerdown снимаем draggable с ближайшего предка-карточки и возвращаем на pointerup — холст рисует, а не тащит блок. Co-Authored-By: Claude Opus 4.8 (1M context) --- frontend/js/svg-draw.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/frontend/js/svg-draw.js b/frontend/js/svg-draw.js index a79c810..5e23533 100644 --- a/frontend/js/svg-draw.js +++ b/frontend/js/svg-draw.js @@ -200,8 +200,23 @@ /* ── drawing interaction ──────────────────────────────────────── */ let drawing = false, startP = null, curEl = null, penPts = null, dragMode = null, dragStart = null, selStartXY = null; + /* The host lesson block-card is draggable=true and hijacks mouse-drag on the + canvas — and its dragstart fires on the CARD (not the svg), so it can't be + cancelled here. Fix: disable the nearest draggable ancestor while a pointer + is down on the canvas, restore on release. */ + let _dragAnc = null; + function suppressAncestorDrag() { + const a = svg.closest && svg.closest('[draggable="true"]'); + if (a) { _dragAnc = a; a.setAttribute('draggable', 'false'); } + } + function restoreAncestorDrag() { + if (_dragAnc) { _dragAnc.setAttribute('draggable', 'true'); _dragAnc = null; } + } + document.addEventListener('pointerup', restoreAncestorDrag); + svg.addEventListener('pointerdown', function (evt) { if (evt.button !== 0) return; + suppressAncestorDrag(); const p = svgPoint(evt); if (state.tool === 'select') { @@ -274,6 +289,7 @@ }); function endDraw(evt) { + restoreAncestorDrag(); if (dragMode === 'move') { dragMode = null; commit(); return; } if (!drawing) return; drawing = false; @@ -466,6 +482,7 @@ function destroy() { document.removeEventListener('keydown', onKey); + document.removeEventListener('pointerup', restoreAncestorDrag); if (root.parentNode) root.parentNode.removeChild(root); }