Bug 15381 - execCommand justify modifies the contentEditable node
Summary: execCommand justify modifies the contentEditable node
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: 523.x (Safari 3)
Hardware: All OS X 10.4
: P2 Normal
Assignee: Nobody
URL: http://www.nick-santos.com/tests/just...
Keywords: GoogleBug
Depends on:
Reported: 2007-10-05 14:04 PDT by Nick Santos
Modified: 2009-02-16 15:42 PST (History)
3 users (show)

See Also:

patch (6.82 KB, patch)
2009-02-12 15:10 PST, Justin Garcia
eric: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Santos 2007-10-05 14:04:00 PDT
Steps to reproduce:
1) Create a contentEditable field with some text, and no display: block elements.
2) In javascript, call document.execCommand("justifyRight", false)

Expected Result:
A block-level element should be created around the text with style='text-align: right'. IE creates a <p> element.

Actual Result:
The contentEditable element has style='text-align: right.'

As a general principle, execCommand should *never* modify the attributes of a node with contentEditable on. There are all sorts of reasons why this is bad: it may change the layout of the field itself, it makes it more difficult to get the contents of the field, etc.

See the demo at the URL.
Comment 1 Justin Garcia 2009-02-12 14:45:54 PST
This shouldn't be too hard to fix, ApplyStyleCommand::moveParagraphContentsToNewBlockIfNecessary just needs to know about this situation.
Comment 2 Justin Garcia 2009-02-12 14:51:25 PST
I'm testing a fix...
Comment 3 Justin Garcia 2009-02-12 15:10:28 PST
Created attachment 27624 [details]
Comment 4 Eric Seidel (no email) 2009-02-13 09:35:59 PST
Comment on attachment 27624 [details]

looks great!  r=me.
Comment 5 Justin Garcia 2009-02-16 15:42:40 PST