views:

69

answers:

1

I'm trying to use contenteditable and styleWithCss.

It doesn't seem to work in webkit.

Anytime I use do an execCommand, it generates a <b> rather than the span I expected.

Here's a demo: http://jsbin.com/izomo/2/edit

Select part of the text, click the bold button, and see the html output.

Is this a bug or am I doing something wrong.

Thank you very much.

A: 

It seems like everything is working as intended. See Bug 13490 on WebKit BugZilla.

EDIT: Support for styleWithCSS was added to WebKit's source in changeset 40560, on 03 February 2009.

That said, it seems like ever since then, no matter what, styleWithCSS is always set to false, whereas before the change, style commands were always applied with CSS, as if styleWithCSS existed but was always set to true.

I even tried rewriting your document.execCommand line as follows, in accordance with the Mozilla documentation:

document.execCommand("styleWithCSS", true, null);
document.execCommand("bold", false, null);

These modified commands still work in Firefox, but not in either Chrome 5 or Safari 5 (both on Windows and installed today).

So, it would seem like this is a WebKit bug.

Christopher Parker
That's for stylewithcss false, I'm trying to do stylewithcss true.
Mark
D'oh! Okay. I'll take a dive.
Christopher Parker
Same bug as original, but now in opposite direction? I updated my answer after some more research. I think the addition of `styleWithCSS` support was supposed to make it configurable, but it's stuck in its default state, which is `false`. (See [Editor.cpp:940](http://trac.webkit.org/browser/trunk/WebCore/editing/Editor.cpp?rev=61418#L940).)
Christopher Parker
Unhappy news, but thank you. I'll accept your answer after the bug gets confirmed.
Mark
Actually your revised command was correct, and that works. Not a bug.
Mark
Odd; wasn't working for me. I wonder if there was something funky going on with JSbin and/or browser cache, because it wasn't working for me... Anyway, glad it worked!
Christopher Parker