When entering cards in the desktop editor, I sometimes insert non-breaking spaces (NBSP), as I’m typing in French and the French language requires a non-breaking space to be inserted between the end of a sentence and some punctuation characters (including ‘?’, ‘!’ and ‘:’).
However, the NBSP is deleted as soon as I type the punctuation mark.
I’m using Anki 25.09.2 (built from source – commit 3890e12) on Ubuntu 24.04.3 LTS x86_64, but this also affects me on Arch GNU/Linux, with the same version of Anki (package anki-bin)
Could you please provide the steps you are performing when seeing this bug, with enough detail so others can try to reproduce it? For example:
What keys are you pressing to insert the non-breaking space character?
Where are you doing this typing? Is it in the regular field or the HTML editor for the field?
I did some testing on the Anki 25.09.2 Mac desktop app:
In the Add window, I pressed the “<>” icon next to a field to expose the HTML editor for the field.
In the HTML editor field, I typed the characters a to insert the letter “a” followed by a non-breaking space character.
I observed that the HTML editor field contained the text a and the regular field contained a .
In the HTML editor field, I then typed the ! character.
I observed that the HTML editor field contained the text a ! and the regular field contained a !.
So, the non-breaking space character did not get deleted when the punctuation mark was typed.
However, I also saw this behavior for alternate steps 4 and 5:
4. Switcing to the regular field, at the end of the existing text I typed the ! character.
5. I observed that the HTML editor field contained the text a ! and the regular field also contained a !.
So, in this alternate procedure I again saw that the non-breaking space did not get deleted when the punctuation mark was typed. However, the non-breaking space did seem to get replaced with a regular space character.
First, I’m using the BÉPO keyboard layout that allows me to enter a non-breaking space using Ctrl+Alt gr.+Space bar (at least using xkb on GNU/Linux). I think xkb actually lets you use this combination to type a NBSP in any layout, but I’m not sure about that. The behaviour I describe also happens when copy-pasting a NBSP in the field.
So when I do the following steps:
Open the “Add card” window (and select “Basic” as card type for instance);
Type some text in the non-HTML field (i.e. the regular field);
While typing the text, type a non-breaking space using Ctrl+Alt gr.+Space bar, then a punctuation symbol, such as ‘!’;
what I observe when looking in the HTML editor field is that a tag is inserted when I type the NBSP, but as soon as I type the ‘!’, the NBSP is replaced by a regular ASCII space.
By the way, doing the same steps as above but in the HTML editor field inserts a NBSP character in the editor, which is replaced by as soon as the field is unfocused.
I can provide screen recordings if necessary
Edit: it seems like putting a regular space at step 3 also adds a tag that gets replaced by a space when typing ‘!’ (or any character). Also, manually replacing a space by a NBSP when there are characters before and after does not changes it back to a space