Caret positioning is incorrect in an empty contenteditable element with ::before pseudo
Categories
(Core :: Layout: Block and Inline, defect, P2)
Tracking
()
| Webcompat Priority | P2 |
| Tracking | Status | |
|---|---|---|
| firefox61 | --- | wontfix |
| firefox62 | --- | fix-optional |
| firefox63 | --- | affected |
People
(Reporter: andyearnshaw, Assigned: emilio)
References
Details
Attachments
(6 files, 3 obsolete files)
Updated•12 years ago
|
Comment 1•12 years ago
|
||
Comment 4•12 years ago
|
||
Comment 5•12 years ago
|
||
Comment 6•11 years ago
|
||
Comment 7•11 years ago
|
||
Updated•11 years ago
|
Comment 10•11 years ago
|
||
Comment 16•11 years ago
|
||
Comment 18•11 years ago
|
||
Comment 21•11 years ago
|
||
Comment 28•10 years ago
|
||
Updated•10 years ago
|
Comment 30•9 years ago
|
||
Comment 31•9 years ago
|
||
Comment 32•7 years ago
|
||
Comment 33•7 years ago
|
||
Comment 34•7 years ago
|
||
Comment 35•7 years ago
|
||
Comment 38•7 years ago
|
||
Comment 39•7 years ago
|
||
Comment 40•7 years ago
|
||
Comment 41•7 years ago
|
||
| Assignee | ||
Comment 42•7 years ago
|
||
Comment 43•6 years ago
|
||
Comment 44•6 years ago
|
||
Comment 45•6 years ago
|
||
@Steven Luscher I found a work using display: flex on the contenteditable element:
https://codepen.io/anon/pen/omqGgL
It may have some side-effects though which I haven't thought about yet.
Updated•5 years ago
|
Comment 46•5 years ago
|
||
So on webcompat we got this testcase.
https://jsfiddle.net/7r13ebp8/
1. Open link and click on text field. 2. See where caret is positioned.In Chrome, it is at the start of placeholder text, on the same line.
In Firefox, it is above, in top-left corner. But when you start typing something, your text appears on the same line. Or if you remove placeholder text, then caret is on the same line too.
The interop stories is not great, but there's no unique scenario for sure. I will repeat my comment from the webcompat issue.
https://github.com/webcompat/web-bugs/issues/48056#issuecomment-590129491
And this is in Safari… which has the same behavior than firefox.
So it's not obvious there is a webcompat issue.
but we could argue that it is more logical to put the caret at the beginning of the placeholder.
When we start typing the line, safari has also a caret which goes from the top of the box to the baseline, while firefox and chrome have a caret which is has big has the characters.
Another difference is if you remove the text after typing it.
- In firefox, the area stays blank with small cursor blinking at the start of the line. If unfocused the line stays blank, caret disappears.
- In chrome, the caret blinks, and the placeholder text reappears, when unfocused, just the caret disappears.
- in safari, same thing than firefox, but with a caret from top of box to the baseline.
| Assignee | ||
Comment 47•5 years ago
|
||
While I'm looking at this code... This fixes the case described in
comment 46.
Updated•5 years ago
|
Comment 48•5 years ago
|
||
Comment on attachment 9145036 [details]
Bug 904846 - Fix caret baseline on a line with only inlines to account for line-height properly. r=jfkthame
Revision D73465 was moved to bug 1634743. Setting attachment 9145036 [details] to obsolete.
Updated•4 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Comment 49•3 years ago
|
||
The severity field for this bug is relatively low, S3. However, the bug has 18 votes.
:emilio, could you consider increasing the bug severity?
For more information, please visit auto_nag documentation.
Comment 51•1 year ago
|
||
(In reply to Steven Luscher from comment #44)
I was hoping that the workaround would work for my use case (simulating an
ellipsis'd::placeholderin a contenteditable<div>) but it did not.
(https://bugzilla.mozilla.org/attachment.cgi?id=9030512)HTML:
<div contenteditable="true" placeholder="Enter text here here here here here here here here..."></div>CSS:
[contenteditable=true]:empty::before{ content: attr(placeholder); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } div[contenteditable=true] { border: 1px dashed #AAA; width: 290px; padding: 5px; white-space: pre-wrap; }
FWIW, changing overflow:hidden to overflow:clip will fix the caret position - tho its not clear why, according to the mdn doc:
Specifying a value other than visible (the default) or clip for overflow creates a new block formatting context. This is necessary for technical reasons; if a float intersects with a scrolling element, it would forcibly rewrap the content after each scroll step, leading to a slow scrolling experience.
I would imagine it might be related to the formatting context somehow...
Comment 52•1 year ago
|
||
As we don't know of any actual sites being affected by this, only codepens, I'm going to remove the webcompat priority for now.
Comment 53•1 year ago
|
||
(In reply to Thomas Wisniewski [:twisniewski] from comment #52)
As we don't know of any actual sites being affected by this, only codepens, I'm going to remove the webcompat priority for now.
I've spent the last couple of days baffled about a particular bug in a private project that is causing content written inside a ContentEditable code block to be written in reverse.
By pure luck this particular 11 year old bug report was bumped up 2 days ago and I just realised this is the root cause of my issue as it makes the caret get stuck on the leftmost position which causes the input to be reversed.
Imagine my dissapointment when i realised this issue (which is now so old that you could register it to middle school) was only bumped up because its priority has been removed. I implore you to please take cases similar to mine and number of votes on this bug report to consideration and re-evaluate the severity and priority of this issue.
Comment 54•1 year ago
|
||
(In reply to Thomas Wisniewski [:twisniewski] from comment #52)
As we don't know of any actual sites being affected by this, only codepens, I'm going to remove the webcompat priority for now.
Tons of websites/web-apps affected. Every contentEditable based editor is affected, and there are so many web components relying on contentEditable "wysiwyg"-like abilities. My own famous Tagify component which is used by tons of people is affected as well: https://github.com/yairEO/tagify
Many SaaS projects are behind a pay-wall and or are aimed for B2B only and are heavily relied on complex web components (unlike simple text-based websites) and this bug probably affect quite of the SaaS products (I've worked on many by many clients of mine)
Comment 55•1 year ago
|
||
Thanks for the insight folks, it's exactly what we need to know to help prioritize these kinds of bug fixes. I'll bump the priority back up now that we know it's definitely causing more pain than we were aware of.
Emilio, would you mind taking another look at this?
Updated•1 year ago
|
| Assignee | ||
Comment 56•1 year ago
|
||
(In reply to Ata Hakcil from comment #53)
By pure luck this particular 11 year old bug report was bumped up 2 days ago and I just realised this is the root cause of my issue as it makes the caret get stuck on the leftmost position which causes the input to be reversed.
WDYM with "causes the input to be reversed"? This is only about the caret position. If you have a repro for that I'm happy to poke.
In any case I think the right thing to do is looking at whether https://hg.mozilla.org/try/rev/6716fc2c18434337eb6c153a380c9ffccc6b6986 still fixes the issue, and whether we can get it landed.
Comment 57•1 year ago
|
||
Thanks for updating the priority!
(In reply to Emilio Cobos Álvarez (:emilio) from comment #56)
(In reply to Ata Hakcil from comment #53)
By pure luck this particular 11 year old bug report was bumped up 2 days ago and I just realised this is the root cause of my issue as it makes the caret get stuck on the leftmost position which causes the input to be reversed.
WDYM with "causes the input to be reversed"? This is only about the caret position. If you have a repro for that I'm happy to poke.
We have a ContentEditable code block as the main component of an editor page. There is an event handler that reads the code block content until the caret and may inject additional content to the contentEditable code block such as autocomplete suggestions at the caret position.
Because of the nature of this component and the dynamic contents inside, we have to prevent the default event handler for keyboard input and insert the new character at the caret position ourselves.
Caret being stuck at the leftmost position means when we try to read the code block contents until the caret, we always read empty string, and it also makes the characters typed by the user to be added to the beginning of the block where caret is stuck.
| Assignee | ||
Comment 58•1 year ago
|
||
https://treeherder.mozilla.org/jobs?repo=try&revision=00570165f1d0893c25db1bf1b5453188fc291da4 is the rebased patch again.
(In reply to Ata Hakcil from comment #57)
We have a ContentEditable code block as the main component of an editor page. There is an event handler that reads the code block content until the caret and may inject additional content to the contentEditable code block such as autocomplete suggestions at the caret position.
Because of the nature of this component and the dynamic contents inside, we have to prevent the default event handler for keyboard input and insert the new character at the caret position ourselves.
Caret being stuck at the leftmost position means when we try to read the code block contents until the caret, we always read empty string, and it also makes the characters typed by the user to be added to the beginning of the block where caret is stuck.
That seems totally unrelated to this bug, assuming I'm understanding correctly. Presumably you're reading the caret position using Selection.focusNode / Selection.focusOffset or so? That seems nothing to do with this bug, this bug is about the caret being mispositioned at paint time. If you could build a test-case for that issue and file a new bug, it'd be appreciated. Feel free to cc me, post it here.
Comment 59•1 year ago
|
||
(In reply to Emilio Cobos Álvarez (:emilio) from comment #58)
https://treeherder.mozilla.org/jobs?repo=try&revision=00570165f1d0893c25db1bf1b5453188fc291da4 is the rebased patch again.
(In reply to Ata Hakcil from comment #57)
We have a ContentEditable code block as the main component of an editor page. There is an event handler that reads the code block content until the caret and may inject additional content to the contentEditable code block such as autocomplete suggestions at the caret position.
Because of the nature of this component and the dynamic contents inside, we have to prevent the default event handler for keyboard input and insert the new character at the caret position ourselves.
Caret being stuck at the leftmost position means when we try to read the code block contents until the caret, we always read empty string, and it also makes the characters typed by the user to be added to the beginning of the block where caret is stuck.
That seems totally unrelated to this bug, assuming I'm understanding correctly. Presumably you're reading the caret position using
Selection.focusNode/Selection.focusOffsetor so? That seems nothing to do with this bug, this bug is about the caret being mispositioned at paint time. If you could build a test-case for that issue and file a new bug, it'd be appreciated. Feel free to cc me, post it here.
Unfortunately I can't come up with a clean POC to demonstrate this as I can't get everything to go precisely wrong with just vanilla JS the way it is going on my current project, but I've taken the following screen recording from a more minimal environment that shows (unless I'm completely misreading what is going on in the background) that my issue is also related to caret being mispositioned at the paint time in same way, although I'm not 100% certain.
When I have time, I'll check if the suggested solution also fixes this problem and if not I'll isolate the issue further and create a new bug report.
| Assignee | ||
Comment 60•1 year ago
|
||
The behavior of the test-cases on the bug is identical to chromium now. That's because empty text nodes on ::before were suppressed in bug 1865668.
| Assignee | ||
Comment 61•1 year ago
|
||
Updated•1 year ago
|
| Assignee | ||
Comment 62•1 year ago
|
||
| Assignee | ||
Comment 63•1 year ago
|
||
This passes try and includes a test, but the test fails.
Comment 64•1 year ago
|
||
Verified this issue and still reproduces on Firefox Nightly. The caret is not correctly positioned for test case
Tested with:
Browser / Version: Firefox Nightly 128.0a1 (2024-05-21) (64-bit)
Operating System: Windows 10 PRO x64
Description
•