The comments says the logic block around that pasteHTML() line is a kludge for a browser bug. I don't know how to reproduce that bug though, so I were to apply a fix here now, I have no way to be certain whether my fix would make that bug appear again. My proposed fix is as follows:
if ( bIsCollapsed )
{
oIERange.moveEnd( 'character', 1 ) ;
oIERange.select() ;
oIERange.collapse( true ) ;
oIERange.select() ;
}
If this does not work, how about this... instead of pasting a non-breaking space to expand the block in the try {...} block, we paste a <span> with a unique id there. Then we use DOM methods to remove it instead of using pasteHTML( '' ).