Hi Franz,
This is indeed a complex issue. It stems from the fact that in HTML/CSS, style properties are additive, rather than toggled - that is, if you have bold set on a style, then you set bold on an inline element inside a paragraph with that style, it will remain bold. This isn’t the only approach; as far as I’m aware OOXML actually does the reverse, where by two bolds cancel each other out.
Regarding styles, the design of the editor (and UX Write in general) was based around a very strong emphasis on the use of styles, explicitly discouraging manual, inline formatting. This philosophy came from the “what you see is what you mean” idea followed by LyX (see
http://www.lyx.org/WhatIsLyX). That’s reflective of my attitude towards document authoring, but as I learnt the hard way from many UX Write users, there are many people who prefer manual (inline) formatting instead. As controversial as the issue of styles vs. direct formatting is, I don’t see a reason why we can’t support both camps, in terms of the capabilities we provide.
A complication with the notion of bold, and other attributes, being in an “on” or “off” state is complicated by the inheritance of those attributes from styles. Actually, there’s three states - “on”, “off”, or “inherited” (this is codified in the CSS specification, albeit in a slightly different form - <b> is actually short-hand for font-weight: bold, and “not bold” is font-weight: normal; inherited is also a valid (and the default) property value).
I think the best solution for when the user toggles bold on or off is to have the editor check what the computed style of the selected text actually is. I think there are some DOM APIs which make it possible to access the computed style; otherwise we may need to implement the algorithm ourselves. If the selected text has a style where bold is on, then pressing bold should turn it off explicitly - that is, adding a <span style=“font-weight: normal”> around the selected text.
I’ve just had a look at your patch and I can see this is basically what you’ve done. One problem I can see however is that if there is text with a normal (non-bold paragraph style), and someone toggles bold on and then off again, they will be left with an extraneous <span style=“font-weight: normal”> in the DOM tree (and resulting HTML file) where it does not serve any function. So I think it would be better to only do this if we know the style is one that has bold set.
(fingerprint 5435 6718 59F0 DD1F BFA0 5E46 2523 BAA1 44AE 2966)