Open Bug 1714913 Opened 3 years ago Updated 3 years ago

Get rid of `EditorBase::mPaddingBRElementForEmptyEditor`

Categories

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

enhancement

Tracking

()

People

(Reporter: masayuki, Unassigned)

References

(Blocks 2 open bugs)

Details

I think that we don't need to keep using mPaddingBRElementForEmptyEditor for both TextEditor and HTMLEditor because:

  1. If TextEditor allows empty text node to be a child of anonymous <div>, the padding <br> element is not required (IIRC, the caret position issue has gone).
  2. If HTMLEditor, it's created only for empty <br> element, and never created for contenteditable. This causes some different behaviors between designMode and contenteditable.
  3. Even if we create the padding <br> element, it can be managed with checking first child of the editing host and flag of the <br> element.
Assignee: nobody → krosylight

It turns out designMode=on still needs a padding <br> or data:text/html,<script>document.designMode="on"</script> does not show the caret at all. So I'd like to remove mPaddingBRElementForEmptyEditor only from TextEditor first, what do you think? (Probably in a different bug.)

Note that doing so won't affect <textarea> since currently EnsurePaddingBRElementInMultilineEditor() still want to insert <br> regardless of emptiness. A check could be added but it could cause inconsistency since nothing removes this type of <br> after insertion. (A textarea would be initialized without <br> but then get a permanent one that never disappears even when it becomes empty.)

Flags: needinfo?(masayuki)

(In reply to Kagami :saschanaz from comment #1)

It turns out designMode=on still needs a padding <br> or data:text/html,<script>document.designMode="on"</script> does not show the caret at all. So I'd like to remove mPaddingBRElementForEmptyEditor only from TextEditor first, what do you think? (Probably in a different bug.)

Sounds reasonable.

Note that doing so won't affect <textarea> since currently EnsurePaddingBRElementInMultilineEditor() still want to insert <br> regardless of emptiness. A check could be added but it could cause inconsistency since nothing removes this type of <br> after insertion. (A textarea would be initialized without <br> but then get a permanent one that never disappears even when it becomes empty.)

Yeah, unfortunately, we need a <br> element at least when there is a last line which is empty. So, I don't think that we can stop using <br> element, but stopping managing the mPaddingBRelementForEmptyEditor as a member may make the code simpler and more stateless since like HTMLEditor, once we failed to handle it, checking the member breaks something.

Flags: needinfo?(masayuki)
Assignee: krosylight → nobody
You need to log in before you can comment on or make changes to this bug.