Bug 31678 - contentEditable doesn't wrap elements around content until after the first line
Summary: contentEditable doesn't wrap elements around content until after the first line
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL: http://www.mozilla.org/editor/midasdemo/
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-19 12:16 PST by Tim McConnell
Modified: 2011-08-19 13:04 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tim McConnell 2009-11-19 12:16:23 PST
For a new contentEditable region, only the second line will be wrapped in a container element (e.g. div or p).

Repro steps:
1) Navigate to http://www.mozilla.org/editor/midasdemo/
2) Click into the CE region and type a line
3) Hit enter and type another line
4) Click "View HTML Source"

Actual: You will see that the first line is not contained in the relevant line element.

Expected: The first line, like the second line, has been wrapped in the editor's line element.

Problem: Because content is not uniformly wrapped, operations that should apply to the current line/block will fail on the first line. Any attempt to walk the DOM to find the parent will reach the contentEditable root.
Comment 1 Aryeh Gregor 2011-08-19 09:08:35 PDT
I specced IE/Opera's behavior, which is to wrap every line in a <p>, including the current one as soon as the user hits enter:

http://aryeh.name/spec/editing/editing.html#the-insertparagraph-command

The relevant case is "If container is not editable or not in the same editing host as node or is not a single-line container:".  This basically wraps the current line in a <p>, although admittedly that's unlikely to be clear on a casual read.

I specced it this way because I agree that it's useful for every line to have a wrapper, so that they can be handled consistently.