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

AI-generated summary

A bug is reported where removing bold or italic formatting while highlighting text results in incorrect post-formatting removal and text highlighting. To reproduce, type text, apply bold/italic formatting, re-highlight the text, and remove the formatting. The expected result is the removal of formatting and highlighting of the entire text, but instead, only part of the text is highlighted. seanblue and Firepup650 have observed that this issue affects both bold and italic formatting, with the left and right characters being deselected.

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)

image

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:

**strong**

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

st**rong**

Which becomes

**rong