-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Too wide highlights on the block-level elements using canvas
#74
Comments
I suppose that this issue might be related to the reason why the Because Firefox has the same exact overhighlighting issue! But it has its own set of exceptions that only contains the UPD: I tried forcefully using the Screen.Recording.2024-03-05.at.19.08.15.movScreen.Recording.2024-03-05.at.19.07.30.mov |
Revisiting this (since I finally have a bit more time now). Yes, the ponyfill was originally intended to remedy this issue. Although it's currently buggy (and may in fact never work with good performance - at least not on large and/or deeply nested markup). Can you elaborate what you mean by:
Do you mean the issue does not happen when using the CSS Custom Highlight renderer? Or that the native browser selection looks ok, while the Canvas rendering has problems? As for a solution: TBH I'm currently out of ideas. It seems to be a more serious problem on FF rather than Chrome. I'd definitely like to get rid of it. But right now... not quite sure how to address it. |
P.S.: as you have probably seen, my initial approach to getting "clean" highlights (in the ponyfill) was to create a copy of the annotated text nodes, temporarily wrap each text node in a SPAN, then get the bounding boxes from the SPANs instead. In theory, this would give you accurate highlight bounds that cover only the text. However, it's crazy inefficient, and breaks all sorts of stuff. In hindsight, I believe it might have been sufficient to just split the range instead. I.e.
Again, in theory, this might give us accurate highlight bounds, might work on Chrome as well as FF, and would be much less disruptive. This, along with an improved merge function, are the two main things I have on my todo list. But it will depend somewhat on my current client's wishlist if/when I can work on it. |
Yep, I meant that one. The issue happens for the canvas renderer when the selection goes over the aforementioned block elements
Yeah, that also might be an option 1 Footnotes
|
Ok, this actually confirms my impression. As weird as it is, here's my observation:
|
P.S.: You may have seen that I added yet another renderer implementation, based on absolutely positioned SPANs. This solves a bunch of issues for us (and perhaps should have been the default solution all along). But since that's also based on querying |
So about this issue... I'm in the process of revising the
My initial gut feeling is that this would be sufficient - and significantly easier (and probably more performant) than splitting the range as discussed above. I might think different after I slept over it, and there are surely a few situations where these simple rules might break. (Rotated text?) But I'll give that a try... |
This doesn't look so bad. Before (broken)Bildschirmaufnahme.2024-08-30.um.13.14.32.movAfter (Chrome)Bildschirmaufnahme.2024-08-30.um.14.14.18.movFirefox drops almost all of the "good" lines, too. Still need to investigate that. But might simply be down to things like rounding errors in the coordinates. |
Now also with Firefox! (I forgot that FF, as opposed to Chrome, has the habit of generating client rects with a height of 0px. That filtered out lines which would "contain" a zero-rect. After removing zero-size rects, all looks fine.) Bildschirmaufnahme.2024-08-30.um.14.21.04.mov |
Issue
When testing the selection I noticed a weird selection quirk that makes the highlighter light up the whole row of the block-level element
Such an issue happens only when you select something before the block-level element and then go over it. When the selection starts on the element - the highlights work fine 👌🏻
Expected selection behavior:
expected.selection.mov
Too wide selection on the block-level elements
unexpected.selection.mov
unexpected.selection.on.divs.mov
Exceptions
For unknown reasons, such an issue doesn't happen for the following block elements:
p
h1
, althoughh2-h6
are also susceptible to the issuefieldset
table
Reproduction
The issue is reproducible on the attached plain HTML example for the
text-annotator
. I also made a branch with a list of all the block-level elements in that HTML example - #73.It's worth mentioning that the issue happens only when you're using the
canvas
.The text was updated successfully, but these errors were encountered: