Editor markup issues when toggling text attributes

AI-generated summary

In the discussion titled “Editor markup issues when toggling text attributes,” Remah reports a bug in Discourse’s editor where toggling text attributes (like bold or italic) causes unexpected selection behavior and even text loss. When bolding and then unbolding text, the editor incorrectly shifts the selection due to removed markup characters — for example, selecting a full line with bolded text at the end results in losing the first two characters of the line. Similar issues occur with italic, though only one character is lost due to single-character markup. Remah notes this is frustrating, especially when selecting entire lines, as it forces reselection before applying other formats. In response, sam announces that multi-line fixes for bold application have been implemented, suggesting progress toward resolving the issue. The problem appears limited to toggling off formatting rather than applying it, and affects both single-line and multi-line selections, particularly when formatted text is at line boundaries. The bug highlights a mismatch between visual selection and underlying markup handling in the editor, which can lead to data loss and workflow disruption for users relying on quick formatting toggles.

It is nice that Discourse allows toggling of text attributes. Many forums I use simply insert the codes around the selected text and do not toggle the attributes if I apply the same attribute to the same selection.

When you bold text and then unbold it, the editor appears to assume only the bolded text is selected. If you select the bold text and the markup the text will be unbolded but the selection is shifted right by the two markup characters that no longer exist so the following text is selected by the four markup characters that no longer exist:

Even worse if you select an entire line when only the last word is bolded then you lose text:

Test bold
No bold text

Lose the first two characters of the line:

st **bold
No bold text

If the bold text is not at the end of the line then I lose no text although the markup could be improved:

Test bold text
No bold text

The same occurs with italic but I only lose one character because the markup is only one character:

est _italic
No italic text

1 Like

This problem still bothers me. :grin:

I often select a whole line so if, for example, I toggle off a format like bold or italic then I have reselect to the text before I can toggle on another format.

We implemented multi line fixes for the bold applying code :confetti_ball:

1 Like