Bug 16049
| Summary: | execCommand('backColor') fails on collapsed selections | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Nick Santos <nicksantos> |
| Component: | HTML Editing | Assignee: | Nobody <webkit-unassigned> |
| Status: | RESOLVED FIXED | ||
| Severity: | Normal | CC: | ap, jparent, justin.garcia, mrowe |
| Priority: | P2 | ||
| Version: | 528+ (Nightly build) | ||
| Hardware: | All | ||
| OS: | OS X 10.4 | ||
| URL: | http://nick-santos.com/tests/background_color.html | ||
Nick Santos
Repro Steps:
1) Place the cursor in a contentEditable element.
2) Execute document.execCommand('backColor', false, '#f00') in JavaScript.
3) Type some text.
Expected Result:
The new text should have a red background.
Actual Result:
The new text keeps the same background.
Notes:
'backColor' works ok when text is actually selected.
If we replace 'backColor' with 'foreColor' in step #2, the new text is red as expected.
Verified on Safari3/Win and Webkit-Nightly/OSX.
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Mark Rowe (bdash)
JSEditor.cpp shows that BackColor and ForeColor have different values for the enabledFn member of their CommandImp:
WebCore/editing/JSEditor.cpp: { "BackColor", { execBackColor, enabledAnyRichlyEditableRangeSelection, stateNone, valueBackColor } },
WebCore/editing/JSEditor.cpp: { "ForeColor", { execForeColor, enabledAnySelection, stateNone, valueForeColor } },
BackColor requires a range selection which would cause the command to be disabled for collapsed selections. The fix here may be as simple as changing the enabledFn to enabledAnyRichlyEditableSelection. A quick test suggests that this gives the same behaviour as IE on the test case.
Eric Seidel (no email)
So it sounds like all this bug needs is some understanding of what a change to enabledAnyRichlyEditableSelection would mean for the rest of the web. :) I guess we solve that with a test case.
Julie Parent
+1 on fixing this. We have horrible, horrible hacks in place to get this working in the Google editor. I'd love to get rid of them!
Justin Garcia
(In reply to comment #1)
> JSEditor.cpp shows that BackColor and ForeColor have different values for the
> enabledFn member of their CommandImp:
>
> WebCore/editing/JSEditor.cpp: { "BackColor", { execBackColor,
> enabledAnyRichlyEditableRangeSelection, stateNone, valueBackColor } },
> WebCore/editing/JSEditor.cpp: { "ForeColor", { execForeColor,
> enabledAnySelection, stateNone, valueForeColor } },
Yikes that's completely wrong, BackColor should have enabledAnyRichlyEditableRangeSelection, and I don't know why ForeColor has enabledAnySelection, it should be disabled in a plain text region too.
Justin Garcia
> BackColor should have enabledAnyRichlyEditableRangeSelection
that should read "enabledAnyRichlyEditableSelection".
Justin Garcia
http://trac.webkit.org/changeset/34682