fix: Selection clicking between blocks #1716
Open
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.
Problem
Currently,
.bn-block-content
elements have 3px of padding above and below them. When clicking this padding below a block, the selection is moved to the end of that block. Likewise, clicking the padding above moves the selection to the start. Because the padding we use only results in 6px of extra space between blocks though, this behaviour makes it seem like the cursor is randomly jumping to the start/end of a block.Solution
This PR fixes this UX issue by changing changing the way in which the extra vertical space is added to blocks with content. Instead of using CSS
padding
, theline-height
is increased. This makes it so the selection instead moves to the position closest to the cursor.Before:
Screen.Recording.2025-05-23.at.21.20.42.mov
After:
Screen.Recording.2025-05-23.at.21.24.42.mov
Caveats
The only side-effect of this is that when the selection is expanded, the blue background is slightly taller (the Playwright snapshot updates show this change).
There are also some slight differences between browsers for how the selection is set:
Screen.Recording.2025-05-23.at.21.30.04.mov
Screen.Recording.2025-05-23.at.21.33.06.mov
Alternatives tried
Using
padding-bottom
instead ofpadding-block
: Caused misalignment with the nested block left borders and background color props. Tried to hack around this by addingpadding-top
to.bn-block-content:first-child
& reducingpadding-bottom
on.bn-block-content:last-child
. However, this caused the side menu to be misaligned, as it expects block content of a given type to always have the same height.Using margin instead of padding: Didn't change the behaviour.
Custom selection handling logic: Was overly complex and somewhat hacky.