fix(ui): restore triple-click paragraph selection#546
Merged
backnotprop merged 1 commit intomainfrom Apr 12, 2026
Merged
Conversation
Switch outside-click dismiss from pointerdown to mousedown and skip on multi-click (event.detail >= 2). The capture-phase pointerdown listener from useDismissOnOutsideAndEscape was calling handleToolbarClose on the 3rd click of a triple-click, which removed the word <mark> and normalised text nodes. That DOM mutation between pointerdown and mousedown reset the browser's click-count tracking, so mousedown fired with detail=1 instead of detail=3 — placing a cursor instead of selecting the paragraph. Using mousedown instead of pointerdown because MouseEvent.detail is spec-guaranteed to carry the click count (UI Events spec), whereas the Pointer Events spec says PointerEvent.detail SHOULD be 0. Multi-click mousedowns are part of an active selection gesture; the web-highlighter CREATE handler already cleans up stale pending highlights when a new selection commits, so the eager dismiss is unnecessary. Side-benefit: touch scroll gestures no longer dismiss the toolbar (browsers suppress compatibility mousedown for scrolls); only taps dismiss. closeOnScrollOut already handles the anchor-scrolled-away case. Regression introduced in 39b63c9. Fixes #544 For provenance purposes, this commit was AI assisted.
dab6375 to
2f4892a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
event.detail >= 2) inuseDismissOnOutsideAndEscapepackages/ui/hooks/useDismissOnOutsideAndEscape.tsRoot Cause
Regression from
39b63c9("dismiss annotation toolbars on outside click and Escape", #182). That commit added apointerdowncapture listener to dismiss the annotation toolbar on outside click. During a triple-click:mouseup— web-highlighter wraps the word in<mark>, toolbar mounts, dismiss hook starts listeningpointerdown(fires beforemousedown) — dismiss hook fires →handleToolbarClose()removes the<mark>and normalises text nodesmousedown— the DOM mutation in step 2 changed the element under the cursor (from<mark>to plain text), resetting the browser's click-count. The 3rd click is treated asdetail=1instead ofdetail=3mouseup—window.getSelection().isCollapsedis true → no highlight → no toolbarFix
Guard
handlePointerDownwithevent.detail >= 2. Multi-click pointerdowns are part of an active selection gesture — the web-highlighter CREATE handler already cleans up stale pending highlights when a new selection commits, so the eager dismiss is unnecessary.Test plan
detailis 0)Fixes #544