Closed Bug 1449874 Opened 7 years ago Closed 1 year ago

Left node should be split node rather than new node?

Categories

(Core :: DOM: Editor, enhancement, P3)

enhancement

Tracking

()

RESOLVED DUPLICATE of bug 1735608
Tracking Status
firefox61 --- affected

People

(Reporter: masayuki, Unassigned)

References

(Blocks 1 open bug, )

Details

(Whiteboard: [h2review-noted])

Attachments

(2 files)

This is potential risk of incompatibility with Chrome and Safari. https://jsfiddle.net/d_toybox/g4fd3nhf/23/ When we split a <p>, we create new node as left node and keep using the split node as right node. When joining them, we remove right node and move its all children to the right node (although, I understand this is not so...). On the other hand, Chrome and Safari create new node as right node and keep using it after joining them. Edge creates both new <p> and removes the original <p> from the DOM tree. According to the mobile's market share, using same behavior as Chrome/Safari must be better.
Priority: -- → P3

I'm running into what I think is the same issue: I'm trying to track when a contenteditable DOM node "becomes empty", so it can evaporate along with its non-editable context; however, a node that's created empty should not evaporate immediately.

Consider this HTML:

<body contenteditable="true">
<div id="x">abc</div>
</body>

which is run with defaultParagraphSeparator set to "div". Moving the caret after "c" and hitting Enter results in

<div id="x">abc</div>
<div><br></div>

which is fine. However, assigning IDs to each DOM node yields:

before:
<div id="x">abc</div> 0

after:
<div id="x">abc</div> 1
<div><br></div> 0

the DOM node that you got by running document.getElementById("x") before hitting Enter is now ===-equal to the second div, which does not have an id, not the one that still has id "x" and content "abc".

In this case, the expected output is:
<div id="x">abc</div> 0
<div><br></div> 1

It's less clear what should happen when the split happens at other positions: splitting before "a" yields

<div id="x"><br></div> 1
<div>abc</div> 0

and splitting after "a" yields:

<div id="x">a</div> 1
<div>bc</div> 0

I think there are two clean approaches we can take: don't reuse DOM nodes at all, or reuse a DOM node only if it inherits the whole content of the original node, i.e. if the split happens before the first or after the last child. Letting the id move to the left while === equality moves to the right is very confusing.

Attached file divid.html (deleted) —

WIP patch to split nodes symmetrically, meaning the left node and right node after a split are both different from the original node.

Note that the id attribute is still broken, see bug 1528483.

i.e. if the split happens before the first or after the last child. Letting the id move to the left while === equality moves to the right is very confusing.

Good point.

I think there are two clean approaches we can take: don't reuse DOM nodes at all, or reuse a DOM node only if it inherits the whole content of the original node

I believe that we should follow the Chrome's behavior for both technical reason and market share reason. (I.e., let's keep using the original node as left node.)

I believe that we should follow the Chrome's behavior for both technical reason and market share reason. (I.e., let's keep using the original node as left node.)

That's not how Chromium behaves in the case where we break before the first character. AFAICS, Chromium

  • reuses the original node as the right node if the split happens before the first character (except if it's an empty node)
  • reuses the original node as the left node otherwise.

Doing it that way would be okay, I guess (and require much of the same changes as my WIP patch has).

Whiteboard: [h2review-noted]
Severity: normal → S3
Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: