Opera: Small space is appended when applying styles to collapsed selections

Description

This bug is a follow up to #253. This specific feature has been introduced for that ticket, but Opera presents a strange behavior.

Steps to Reproduce

Load sample01.html;

Place the cursor in the middle of the word "some". For example, after the "o";

Press CTRL+B several times. The toolbar will behave correctly to the command, but note that a small space is added for each time it get pressed.

Analyzing the DOM after CTRL+B, all we have is "so<b></b>me", with the selection inside <b>. That was our intention, but the small space get rendered for the empty <b>.

The code which applies the style can be found in the "_ApplyInlineStyle" function in fckstyle.js. It can be condensed to the following code, which is the only way we have found to make it work with Opera:

But we still have the undesired whitespace behavior. Not only, if we move the caret to the right with the keyboard right after pressing CTRL+B, when returning to the left, the cursor will fell inside the empty <b></b>, which is also not desired. It must simply be ignored when moving the caret, as it does with IE, FF and Safari.

To note that, empty <b></b> is ignored when loading a document with it. It is not being ignored only at our style case, probably because it contains an empty text node inside of it.

I can no longer reproduce the "extra whitespace on multiple ctrl-b" issue with that test case but I can in the editor :(

I don't quite understand the code for inserting/removing styles. It is very complex. As far as I can see, on Ctrl-B FCKCoreStyleCommand.Execute runs but IsActive is only false on the first Ctrl-B. On all subsequent calls it is true, so new keypresses will try to remove the B tag again and again, and apparently fail to do so. RemoveFromRange is called, it creates a "bookmark" SPAN inside the B tag and moves it outside the B tag, then removes it again.

According to Firebug, the empty B tags are not removed in Firefox either, but the input cursor is placed outside the tag. Is this how it is meant to work?

I can no longer reproduce the "extra whitespace on multiple ctrl-b" issue with that test case but I can in the editor :(

The TC is not really related to multiple whitespaces and CTRL+B. Actually, you should not use CTRL+B on the TC, as it will be triggering Operas CTRL+B action. In the TC you can not only one whitespace added when loading the page.

I don't quite understand the code for inserting/removing styles. It is very complex.

Ohh yes it is. It gave me lots of sleepless nights :)

As far as I can see, on Ctrl-B FCKCoreStyleCommand.Execute runs but IsActive is only false on the first Ctrl-B. On all subsequent calls it is true, so new keypresses will try to remove the B tag again and again, and apparently fail to do so. RemoveFromRange is called, it creates a "bookmark" SPAN inside the B tag and moves it outside the B tag, then removes it again.

According to Firebug, the empty B tags are not removed in Firefox either, but the input cursor is placed outside the tag. Is this how it is meant to work?