Editor: Backspace key unexpectedly deletes line-breaks above caret that were created using Shift+Enter

Steffen

Well-known member
Affected version
2.2.9
At the end of this line I'll hit Shift+Enter (not just Enter) twice to create two line-breaks.

Now when I hit the delete key anywhere in this line here, one of the two line-breaks above is removed unexpectedly.

It seems like Enter creates a new paragraph (<p>) whereas Shift+Enter creates a line break (<br>).

Don't ask me why you should use Shift+Enter instead of just Enter in the first place. All I know is that this is driving some of our users nuts. Anyhting you can do about this? :)
 

Attachments

  • Screencast_from_05-09-2022_042656_PM.webm
    23.4 KB

El Porcharo

Well-known member
I've been facing this issue for a while now, and I see that this thread didn't get a reply at all.

This is kind of frustrating when typing, I know it might not be so popular to add an empty line by pressing SHIFT+ENTER, but sometimes I do since I got used to it on messaging apps.

I can see even the official XF is affected (video below), can't say exactly from which version I started facing this issue on my board but it must be not later than a couple of updates.

Please take a look into it.


 

scriptop

New member
Managed it somehow. You can add this after <head> in PAGE_CONTAINER.

Code:
<script>
    window.addEventListener('keydown', function (e) { e.stopPropagation(); }, true);
    window.addEventListener('keyup', function (e) { e.stopPropagation(); }, true);
    window.addEventListener('keypress', function (e) { e.stopPropagation(); }, true);
</script>

Don't ask why/how it fixes it, I don't know.
 

webbouk

Well-known member
I've had this and thought it was a bug in Firefox. The above fixes it.

Is it possible to add the above into extra.less so that future updates don't override the addition?
 

scriptop

New member
Previous code was broke some another things. Here is code to restrict SHIFT + ENTER in the editor

JavaScript:
<script>
function isEnterShiftPressed(event) {
    if ((event.key === 'Enter') && (event.shiftKey))
        return true;

    return false;
}

function isEditor(event) {
    if (event.target == document.querySelector('.fr-element'))
        return true;

    return false;
}

window.addEventListener('keydown', function (event) { if (isEnterShiftPressed(event) && isEditor(event)) { event.preventDefault(); event.stopPropagation(); } }, true);
window.addEventListener('keyup', function (event) { if (isEnterShiftPressed(event) && isEditor(event)) { event.preventDefault(); event.stopPropagation(); } }, true);
window.addEventListener('keypress', function (event) { if (isEnterShiftPressed(event) && isEditor(event)) { event.preventDefault(); event.stopPropagation(); } }, true);
</script>
 
Top