From 53cd202a93e751bc8b79069c152d2d5bbd1a8ead Mon Sep 17 00:00:00 2001 From: Bruno Charest Date: Sat, 6 Jun 2026 00:04:04 -0400 Subject: [PATCH] fix: bubble menu always positioned at selection end Changed from selectionStart to selectionEnd so bubble follows where user finished selecting. Removed broken fallback that repositioned to textarea bottom on every scroll. Simple viewport clamp instead. --- frontend/editor-poc.html | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/frontend/editor-poc.html b/frontend/editor-poc.html index b09d885..5ee8c73 100644 --- a/frontend/editor-poc.html +++ b/frontend/editor-poc.html @@ -782,15 +782,14 @@ body { font-family: var(--sans); background: var(--bg); color: var(--text); heig // ---- Bubble menu ---- function showBubble() { if (ta.selectionStart === ta.selectionEnd) { hideBubble(); return; } - // Position below the selection start, using caret pixel calc - var pt = caretToPixel(ta.selectionStart); - // Convert from editorWrap-relative to viewport-relative + // Position below selection END (where user finished selecting) + var pt = caretToPixel(ta.selectionEnd); var wr = editorWrap.getBoundingClientRect(); var top = wr.top + pt.y + 4; var left = wr.left + pt.x - 10; - // Fallback if caret calc gives odd values - if (top < 50) { var tr = ta.getBoundingClientRect(); top = tr.bottom + 6; left = tr.left + (tr.width / 2) - (bubble.offsetWidth / 2); } - if (top + 36 > window.innerHeight) top = top - 60; + // Clamp to viewport (never use textarea fallback) + if (top < 60) top = 60; + if (top + 40 > window.innerHeight - 10) top = window.innerHeight - 50; if (left < 6) left = 6; if (left + bubble.offsetWidth > window.innerWidth - 6) left = window.innerWidth - bubble.offsetWidth - 6; bubble.style.left = left + 'px'; bubble.style.top = top + 'px';