Work-around for backspacing empty lines in Firefox
authorAlexander Ebert <ebert@woltlab.com>
Mon, 23 Jul 2018 14:00:11 +0000 (16:00 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 23 Jul 2018 14:00:11 +0000 (16:00 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js

index d21246b7941a20e11fc98301d51c41295e6c5aeb..bb6bcc6b3ff6d3b46885f1003d93e2262387c47a 100644 (file)
@@ -129,6 +129,7 @@ $.Redactor.prototype.WoltLabKeydown = function() {
                                // is flawed when the previous element is a list. Their current implementation
                                // inserts the content straight into the list element, rather than appending it
                                // to the last possible location inside a <li>.
+                               var br = null;
                                if (e.which === this.keyCode.BACKSPACE && this.detect.isFirefox()) {
                                        var block = this.selection.block();
                                        if (block && block.tagName === 'P' && this.utils.isStartOfElement(block)) {
@@ -148,6 +149,13 @@ $.Redactor.prototype.WoltLabKeydown = function() {
                                                        e.preventDefault();
                                                        return;
                                                }
+                                               else if (previousBlock && previousBlock.nodeName === 'P') {
+                                                       // Firefox moves the <br> of a previous <p><br></p> into the current container instead of removing the <br> along with the <p>.
+                                                       br = previousBlock.lastElementChild;
+                                                       if (br !== null && br.nodeName !== 'BR') {
+                                                               br = null;
+                                                       }
+                                               }
                                        }
                                }
                                
@@ -198,6 +206,12 @@ $.Redactor.prototype.WoltLabKeydown = function() {
                                                }
                                        }
                                }
+                               else if (br !== null && this.detect.isFirefox()) {
+                                       var range = selection.getRangeAt(0);
+                                       if (range.startOffset === 1 && range.startContainer.firstElementChild === br) {
+                                               elRemove(br);
+                                       }
+                               }
                        }).bind(this);
                        
                        var ua = window.navigator.userAgent.toLowerCase();