Removing bold/italics formatting while highlighting * results in wrong post-format-removal text highlighting

This one is a little weird, but I noticed it along with Ctrl+I replaces bold formatting instead of adding additional formatting.

Steps to reproduce:

  1. Type “test” and highlight it
  2. Hit Ctrl+B to get **test**
  3. Highlight the entire text **test** (this is admittedly a bit weird when done right after applying the bold formatting, but in a normal workflow I think it can happen more reasonably)
  4. Hit Ctrl+B to remove the bold formatting

Expected: The ** formatting is removed and the whole word test is highlighted
Actual: The ** formatting is removed, but only st is highlighted (which means you can’t apply additional formatting on the word without fixing the highlighting first)


Note that the same happens with Ctrl+I for italics, but est is highlighted at the end, so it appears to be affected by how many formatting characters are removed.

It seems to specifically deselect the left 2 and right two chars, for example:


Deselects the st. Re-bolding and then selecting all again, then de-bolding takes off the right two chars incorrectly.


Which becomes