Formatting lost on backspace bug.
See original GitHub issueI’ve noticed some odd behaviour with TinyMCE editors (4.2.5) that seems to be present in the most recent versions and was wondering if this is a bug and/or changeable behaviour.
Basically what I’m seeing is that if I have a line of formatted text and press return (more than once) midway through that sentence and then hit backspace the formatting for that text is lost.
The HTML at each stage looks like thus:
Formatted line:
<p><span style="font-family: 'arial black', sans-serif; font-size: 14pt;" data-mce-style="font-family: 'arial black', sans-serif; font-size: 14pt;" id="ext4-ext-gen4618">I am a line of text</span><br data-mce-bogus="1"></p>
After 2 carriage returns (as expected):
<p><span style="font-family: 'arial black', sans-serif; font-size: 14pt;" data-mce-style="font-family: 'arial black', sans-serif; font-size: 14pt;" id="ext4-ext-gen4618">I am a line </span></p>
<p><span style="font-family: 'arial black', sans-serif; font-size: 14pt;" data-mce-style="font-family: 'arial black', sans-serif; font-size: 14pt;"><br data-mce-bogus="1"></span></p>
<p><span style="font-family: 'arial black', sans-serif; font-size: 14pt;" data-mce-style="font-family: 'arial black', sans-serif; font-size: 14pt;" id="ext4-ext-gen4618">of text.</span><br data-mce-bogus="1"></p>
Once backspace is hit (with caret at front of last line) it becomes:
<p><span style="font-family: 'arial black', sans-serif; font-size: 14pt;" data-mce-style="font-family: 'arial black', sans-serif; font-size: 14pt;">I am a line </span></p>
<p>of text.<br></p>
As you can hopefully see all of the formatting was stripped from the “of text.” line and this is not what I’d want to see, what I’d like is for it to look as it would after a single carriage return keeping its formatting ie:
<p><span style="font-family: 'arial black', sans-serif; font-size: 14pt;" data-mce-style="font-family: 'arial black', sans-serif; font-size: 14pt;">I am a line </span></p>
<p><span style="font-family: 'arial black', sans-serif; font-size: 14pt;" data-mce-style="font-family: 'arial black', sans-serif; font-size: 14pt;">of text.</span></p>
Any insight you have would be appreciated.
Video of the problem: https://www.youtube.com/watch?v=-9AHNo-E4NY
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:6 (1 by maintainers)
I am working to try and fix #3817 at the moment. I think these issues might be related
As a workaround, I had solved it using the keydown event:
ed.on("keydown",function(evt) { if (evt.keyCode == 8 || evt.keyCode == 46) //backspace or delete { var elem = tinyMCE.activeEditor.selection.getNode(); if (elem.textContent.length <= 1) { evt.preventDefault(); evt.stopPropagation(); jQuery(elem).html(''); // inserting Zero Width No-Break Space return false; } } });
Hope this helps.