Repository navigation
Conversation
Vedthakar
force-pushed
the
fix/7758-hr-gap-click
branch
2 times, most recently
from
October 16, 2026 03:30
cb65a06 to
63ef73a
Compare
…rule when clicking the empty space above or below it A click in the gap above or below a horizontal rule (its margins) lands on the parent element, so the CLICK_COMMAND handler, which only checked for the <hr> itself, ignored it. Where the browser then puts the caret differs between Chromium and Firefox, so the handler now hit tests the click against each child rule's box extended by its margins and selects the nearest one, matching the arrow keys. Shift-click still extends the range, and a click below a rule that is the last block still inserts a paragraph. Selecting the rule from the click handler builds on meta#8967 by @LeSingh1. Signed-off-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com> Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Vedthakar
force-pushed
the
fix/7758-hr-gap-click
branch
from
October 21, 2026 21:37
63ef73a to
e0fa25f
Compare
Owner
Author
|
Superseded by meta#9422. |
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.
Description
This solves issue meta#7758: clicking the empty space above or below a horizontal rule now selects the rule, which is what the arrow keys already do from those spots.
Current behavior. A horizontal rule is a block decorator with vertical margins. A click in the margin above or below it doesn't land on the
<hr>. It lands on the parent element (the root in the playground), and the caret ends up wherever the browser decides. Onmainin Chromium and Firefox:root:1), drawn as a block cursor, so it looks like it is on the rule (the recording in the issue)@etrepum's expected behaviour on the issue is that clicks should be handled "in the basically same way that the arrow keys are… there are just 'empty' locations between the divider and any adjacent block element node". That covers both sides of the rule.
Root cause. The
CLICK_COMMANDhandler inHorizontalRuleExtensiononly selects the rule whenevent.targetresolves to theHorizontalRuleNode. A click in the gap targets the parent element, so the handler returnsfalse.Why a hit test, not the caret. meta#8967 selected the rule from the caret the click produced. It was folded into meta#9053, and its HR part was dropped with this note: the caret offset in that blank space "is precisely what browsers disagree about… so selecting the rule reliably needs a hit test against the rules' own geometry, which is a different change and belongs in its own PR." This is that PR. The handler doesn't look at the caret at all, so the result doesn't depend on where Chromium, Firefox or WebKit put it.
What this changes.
<hr>),$getHorizontalRuleAtClickchecks that element's childHorizontalRuleNodes. It takes each rule'sgetBoundingClientRect(), extends it by the rule's computed margins, and selects the rule whose box contains the click. If two rules' margins overlap, the one nearer to the click wins.ClickAfterLastBlockExtensionis enabled, as it is in the playground. That extension claims the click and stops Lexical's click handling. Without it, the click selects the rule.<hr>and shift-click toggling are unchanged, and so are clicks inside text.Behaviour change for meta#6775 (intentional). A click between two adjacent rules used to leave a root caret between them. It now selects the nearer rule, which is consistent with the gap next to any other block. Adding content between two rules still works: with the rule selected, Enter inserts a paragraph after it. The meta#6775 test checks this now, as well as the original point of meta#6775 (the click gives a selection, not
null).This likely also fixes meta#6689 (clicking just above the left part of a rule selects
root), which is the same click as the "above" case here. I haven't marked it as closed.The deprecated
@lexical/react/LexicalHorizontalRuleNodeis not changed. The playground andHorizontalRuleExtensionusers get the fix.Credit. Selecting the rule from the click handler, and the e2e test shape, build on meta#8967 by @LeSingh1.
Closes meta#7758
Test plan
New e2e tests in
packages/lexical-playground/__tests__/e2e/HorizontalRule.spec.mjs, under "Clicking the empty space beside a horizontal rule (meta#7758)". Each click point is computed from the middle of the gap itself, not a fixed pixel offset:NodeSelectionof thehorizontalrule, plus thehrSelectedclass)RangeSelectionacross the rule)Updated "Clicking between consecutive block decorators creates selection (meta#6775)": it now expects the nearer rule to be selected, then presses Enter and checks that a paragraph sits between the two rules (
hr + p + hr).Before
On
mainwith the tests applied and the source change reverted. I ran this locally in Chromium and Firefox:Firefox gives the same 3 failures and 3 passes. The 3 passing cases are behaviour this PR keeps.
After
On browser coverage: I checked the Firefox "before" and "after" results locally only. CI on my fork runs only the Chromium canary e2e job, because the extended Firefox/WebKit workflow only runs in the facebook org. I couldn't run WebKit locally because its system dependencies aren't installed on my machine, so WebKit is left to upstream extended CI. The hit test doesn't depend on browser caret placement, which is what differed between browsers before.
Author: Ved Thakar (@Vedthakar)