Fix: Blocks of multi-line inline elements are too large #18
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
Blocks of multi-line inline elements can be broken even if they don't look collided with the ball in some cases.
Here's an example reproduced by the
controlMode: "mouse"
feature created in #15, and hard-codingvisualizeBlocks: false
(checkout my debug branch if you reproduce by yourself):As you can see, the larger block
12345678901234567890
got broken just as the12345
got hit.The source of the screenshot HTML is here.
Cause
This is because the blocks of elements are created from the rectangles returned by
getBoundingClientRect
, which returns only one rectangle from an element.getBoundingClientRect
doesn't have a problem with most elements, each of which has only one bounding rectangle. But given a multi-line element,getBoundingClientRect
returns an unexpectedly large rectangle including its rightmost bottom edge.Solution
Use
getClientRects
instead ofgetBoundingClientRect
to create blocks. It returns all rectangles of elements including multi-line elements.NOTE