Delete key reorders elements
Categories
(Core :: DOM: Editor, defect, P2)
Tracking
()
People
(Reporter: saschanaz, Unassigned)
References
Details
Repro: https://codepen.io/SaschaNaz/pen/ZEGrLOq
- Put a
<p>
inside<span>
, like<span>foo<p>bar</p></span>
- Focus on the first line
- Tap End key
- Tap Delete key.
Expected: <p>
should be merged into <span>
.
Actual: <p>
moves to the front of <span>
.
This is essentially Bug 200416 but with Delete key.
Reproducible on Ubuntu 18.04 too.
Reporter | ||
Comment 2•5 years ago
•
|
||
atLeftBlockChild
inside TryToJoinBlocksWithTransaction
gets wrong value:
- The code tries merging the parent
<div>
of<span>
with<p>
, instead of just<span>
with<p>
- The offset is computed against
<div>
and<span>
usingatLeftBlockChild
, where<span>
is in the parent of<p>
. - So the code moves
<p>
to the offset:SplitInlinesAndCollectEditTargetNodesInOneHardLine
splits<span>
to make a new<span>
that only includes<p>
, and store it inarrayOfContents
.- As
HTMLEditor::NodeIsBlockStatic
check fails, the code moves the new<span>
without peeling any block.
Reporter | ||
Comment 3•5 years ago
|
||
Tried reusing the utility added by Bug 200416 but it's broken too. Backspace also splits <span>
and even adds additional unexpected empty spans. Still investigating.
Reporter | ||
Comment 4•5 years ago
|
||
Oh wait. Chrome and Safari also do not join <span>
and <p>
, instead they peels <p>
and moves its children next to <span>
.
Seems WPT has no relevant test for this.
Reporter | ||
Comment 5•5 years ago
|
||
I think the right fix here is to merge <span>
and <p>
. The proper result should be <span>foobar</span>
instead of current Chrome/Safari behavior resulting <span>foo</span>bar
, because the latter gives more complex tree change and also potentially affect styling.
But some questions:
- Am I right that there is no spec defining this behavior, as contentEditable=true spec is archived and defines nothing?
- Could there be a good reason to keep Chrome/Safari behavior e.g. consistency with other existing behavior?
- If not, should we still keep compatibility with Chrome or can we fix this in my suggested way? I know this is just an edge case that shouldn't occur frequently, but would there still be a web compat problem from this?
Comment 6•5 years ago
|
||
(In reply to Kagami :saschanaz from comment #5)
I think the right fix here is to merge
<span>
and<p>
. The proper result should be<span>foobar</span>
instead of current Chrome/Safari behavior resulting<span>foo</span>bar
, because the latter gives more complex tree change and also potentially affect styling.
I also think that Chrome/Safari's behavior does not make sense. But I wonder, what's your expected result for <span>foo[]<p>bar</p>baz</span>
when Delete
pressed at the caret position []
. I think that it's reasonable to make them 2 lines, first line is "foobar" and second line is "baz" from point of view of users. But if <p>
is merged to <span>
, sounds like that "baz" also coming to the first line. Perhaps, needs to insert a <br>
for the second line?
But some questions:
- Am I right that there is no spec defining this behavior, as contentEditable=true spec is archived and defines nothing?
IIRC, there has not been any WD spec defining each edit action behavior details.
- Could there be a good reason to keep Chrome/Safari behavior e.g. consistency with other existing behavior?
- If not, should we still keep compatibility with Chrome or can we fix this in my suggested way? I know this is just an edge case that shouldn't occur frequently, but would there still be a web compat problem from this?
For web-compat and if Chrome/Safari's behavior is reasonable, we should follow them. But like this case, if their behavior does not make sense, it's difficult to consider. But I guess that it's fine to take different behavior for this case because the situation must be rare in existing web apps.
Once we take hacky fix for emulating odd behavior of them, such hack must block more important fixes.
Reporter | ||
Comment 7•5 years ago
|
||
I think that it's reasonable to make them 2 lines, first line is "foobar" and second line is "baz" from point of view of users.
True, I filed Bug 1624883 for that.
Once we take hacky fix for emulating odd behavior of them, such hack must block more important fixes.
Agreed. I'll try making this right.
Updated•2 years ago
|
Description
•