Bug 23997 - Inserting spaces at end of line, causes spaces to wrap in designMode, but not contentEditable
Summary: Inserting spaces at end of line, causes spaces to wrap in designMode, but not...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac OS X 10.5
: P2 Normal
Assignee: Nobody
URL: http://www.mozilla.org/editor/midasdemo/
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-17 15:15 PST by Eric Seidel (no email)
Modified: 2011-08-19 12:38 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 Eric Seidel (no email) 2009-02-17 15:15:45 PST
Inserting spaces at end of line, should never cause spaces to wrap

See test case.

WebKit currently wraps the last space before a word, if that space happens to have been converted into a nbsp by the space balancing algorithm.  FF will wrap whole blocks of spaces inserted at the end of line.  IE7 of course does something completely different.  Word (2003 win and 2008 mac) and TextEdit collapse spaces at end of line until a word before the space causes a wrap (or you insert a newline).

I suggest we match Word.
Comment 1 Eric Seidel (no email) 2009-02-17 15:23:22 PST
The example which fails in Safari is:

"foo  bar"

the space before "bar" will wrap with bar at times.
Comment 2 Ojan Vafai 2009-02-17 15:25:42 PST
Looks like contentEditable does the word/textedit behavior and designMode does not. Specifically, there are a couple of CSS properties that get applied when it's contentEditable that dont' when it's designMode.

designMode should really work exactly like contentEditable on the body.
Comment 3 Eric Seidel (no email) 2009-02-17 15:49:11 PST
Agreed.  We should probably spec out (as part of our current editing specing effort) that setting document.designMode = "true" is identical to setting document.body.contentEditiable = true;  Such that if you remove the body, design mode turns off.  I'm not sure that would match IE, but I would suspect it would be less confusing, and in all practical cases identical.
Comment 4 Ojan Vafai 2009-02-17 15:59:37 PST
According to MSDN documentation on contentEditable:
"If this attribute is applied to a BODY element, it has the same effect as setting the designMode property of the document object."

 http://msdn.microsoft.com/en-us/library/ms537837(VS.85).aspx

Comment 5 Aryeh Gregor 2011-08-19 12:38:42 PDT
(In reply to comment #1)
> The example which fails in Safari is:
> 
> "foo  bar"
> 
> the space before "bar" will wrap with bar at times.

The way I worked around this in my editing spec is . . . messy, but it avoids this problem:

http://aryeh.name/spec/editing/editing.html#canonical-space-sequences

Effectively, I make sure that runs of whitespace are normalized such that there's never an nbsp immediately before a word.  If the user types a bunch of consecutive spaces in between two regular words, they become

 _
 *_
 _*_
 _**_
 _*_*_
 _*_**_
 _*_*_*_
 _*_*_**_

etc., where _ is a regular space and * is non-breaking.  This does cause runs of spaces to wrap sometimes, but it minimizes the pain.

I don't see any way around all this stuff.  You can't just match Word here, because the content has to look the same if contenteditable is set to false, and in that case we have to follow regular HTML rendering rules.  That means we have to do something within CSS, but also supporting non-CSS clients if possible.  So horrible nbsp hacks are the only option.  Discussion:

http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2011-June/032187.html

My conclusion is that authors who want sane behavior have to set white-space: pre-wrap on the editable area and also on any place where they use the output (so that it looks the same).