Right-click on mind-map node sometimes shows wrong context menu #154
Labels
No labels
prio_critical
prio_low
type_bug
type_contact
type_issue
type_lead
type_question
type_story
type_task
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lhumina_code/hero_whiteboard#154
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Right-clicking a mind-map node should consistently show the per-node menu (Add Comment, Delete Node, etc.). Currently, sometimes it shows the mindmap-group context menu instead, depending on where the click lands or the order of event handlers.
Expected
Right-click on any mind-map node (root, branch, leaf) — including on the text label, the rounded rect, anywhere inside the node — always opens the per-node menu wired in
mindmap.js(showNodeContextMenu).Actual
Sometimes the click is captured by the parent group / canvas before the node-level handler runs, and the user sees a different menu (the canvas-level or group-level right-click menu).
Repro
Likely root cause: event bubbling. The node rect has a
contextmenuhandler but the labelKonva.Textdoes not, so right-click on the label propagates to the parent group / stage, where another handler may run.Implementation Spec
Root cause
In
crates/hero_whiteboard_ui/static/web/js/whiteboard/mindmap.jsonlynodeRecthas acontextmenulistener (around line 424). The other Konva sub-shapes inside the same Konva.Group — the labelKonva.Text, the collapse indicator (+/−), the add-child+button, and the comment icon (💬) — have nocontextmenulistener.The competing handler is the document-level listener in
crates/hero_whiteboard_ui/static/web/js/whiteboard/contextmenu.js(~line 15):The node-level handler calls
e.evt.preventDefault()+e.evt.stopPropagation(), which is what stops the document handler — but only when the right-click hitsnodeRectdirectly. When the cursor is over the label, the toggle, the add-child button, or the comment icon, Konva's intersection returns that child, no Konva listener fires, the DOM event is neverpreventDefault-ed, and the document-level handler shows the generic per-object canvas menu. (e.cancelBubble = truecontrols Konva-internal bubbling, not the native DOM event — the load-bearing calls are one.evt.)Approach
Extract the existing handler into a small local function and attach it to every per-node sub-shape (
nodeRect,label,indicator,addBtn,commentIcon).Why not attach to the parent
group:groupis the single mindmap-object Konva.Group shared by all nodes plus the title, direction-flip arrow, background, and connector lines. A handler ongroupwould fire for right-clicks on the title, flip arrow, blank background, or connectors too — wrong. Per-shape attachment matches the existing pattern (thedblclickhandler is already duplicated onnodeRectandlabel).Files to Modify
crates/hero_whiteboard_ui/static/web/js/whiteboard/mindmap.js— only this file.Implementation Plan
Step 1 — wire
contextmenuon every per-node shapeFiles:
mindmap.jsIn
drawNodes:nodeRect.on('contextmenu', ...)withnodeRect.on('contextmenu', onNodeContextMenu);.label.on('contextmenu', onNodeContextMenu);.if (node.children && node.children.length > 0)block, after theindicatoris added:indicator.on('contextmenu', onNodeContextMenu);.addBtnis added:addBtn.on('contextmenu', onNodeContextMenu);.if (node.comment)block, aftercommentIconis added:commentIcon.on('contextmenu', onNodeContextMenu);.Leave all other handlers (
click,dblclick,dbltap,mouseenter,mouseleave) intact.Acceptance Criteria
Right-clicking on each of these node surfaces must show the per-node menu (Add/Edit Comment, Add Child, Delete Node) — never the canvas/object menu:
+/−indicator (when present)+buttonAnd the following must continue to show the canvas/object menu (intentionally not per-node):
mm-title)mm-flip)What NOT to break
dblclick/dbltap) onnodeRectandlabel— independent.indicator,addBtn,commentIcon— Konva firesclickonly on left mouseup; adding acontextmenulistener does not steal left clicks.contextmenudoes not initiate drags.contextmenu.js— unchanged.Validation
cargo check --workspacecargo test --workspace --libImplementation summary
Changes
crates/hero_whiteboard_ui/static/web/js/whiteboard/mindmap.js— extracted the existing per-nodecontextmenuhandler into a localonNodeContextMenufunction and attached it to every per-node sub-shape:nodeRect,label,indicator(when present),addBtn, andcommentIcon(when present). Right-click hits on any of these nowpreventDefault+stopPropagationthe native event so the document-level handler incontextmenu.jsno longer fires the canvas/object menu.Validation
cargo check --workspace: passcargo test --workspace --lib: passNotes
Intentionally not changed: right-click on the mindmap title text (
mm-title), the direction-flip arrow (mm-flip), connector lines, and the empty area inside the mindmap's bg rect — those continue to show the canvas/object menu (no per-node target there).The handler is shared by all per-node shapes, so locked-node behavior, double-click-to-edit, single-click handlers on the toggle / add / comment icons, and drag-start on the parent group are all unaffected.