Unable to insert a non-breaking spaceSee original GitHub issue
I’m trying to use “Alt-Space” to add an HTML
code, which is standard usage for people who write in French (where they put non-breaking spaces in front of punctuation marks like “?”, “:”, “!” and others. But I’m unable to do this
If I take a normal Trumbowyg box and type “F r e d Alt-Space ?”, this results in a normal space for the html:
If I change this to “F r e d Alt-Space Space ?”, the result changes:
But I cannot see any way of getting the desired result:
I’ve succeeded in writing some custom code to trap character code 160, but I then can’t see how to insert an
into the text and set the caret to immediately after it: there isn’t enough documentation on the Range API to make it obvious how I do this.
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
I’ve done a bit more digging: as ever, the article on French Wikipedia is fairly comprehensive. As far as I can see, the Unicode value of 160 is pretty much universal, the keyboard shortcuts vary wildly from one system to another (it’s Alt-0160 on Windows). The English Wikipedia article gives similar information.
The following code works fine, with one whoopsie (
trumbois my editor class).
The whoopsie is that if the added is the last thing in the paragraph, when you type the next character (for example, an exclamation mark), the is changed to a space. If you then go back, delete the space and type “ALT-Space” again, everything is now fine.
The workaround is enough to get me out of jail for now, but it would be nice if you can find a better solution.
Hi Alex, I know it’s been a long time, but I’ve got round to looking at this again. If you start with an editor containing the following html
<p>a </p>…and then move your cursor to the end after the non-breaking space and type the letter ‘b’, what you get is
<p>a b</p>The place where this happens is in the following routine:
t.$ed.html()appears to convert the non-breaking space into a standard space.
If I’m not mistaken, the html() function is the one in jQuery, so it may be relevant to know that my jQuery version is 3.6.0.
Do you have any ideas on why the html() function is behaving like this, and what I might be able to do about it?