Fixed backspace behavior for last block that is not a paragraph
authorAlexander Ebert <ebert@woltlab.com>
Thu, 8 Sep 2016 16:26:33 +0000 (18:26 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 8 Sep 2016 16:26:33 +0000 (18:26 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js

index 06572bc74f5f0549953a4f246514898b103da5ce..e0a6f94172f49a5596e4c9972607886910acf23d 100644 (file)
@@ -180,6 +180,21 @@ $.Redactor.prototype.WoltLabKeydown = function() {
                                return mpOnTab.call(this, e, key);
                        }).bind(this);
                        
+                       var mpFormatEmpty = this.keydown.formatEmpty;
+                       this.keydown.formatEmpty = (function (e) {
+                               // check if there are block elements other than <p>
+                               var editor = this.$editor[0], node;
+                               for (var i = 0, length = editor.childElementCount; i < length; i++) {
+                                       node = editor.children[i];
+                                       if (node.nodeName !== 'P' && this.utils.isBlockTag(node.nodeName)) {
+                                               // there is at least one block element, treat as non-empty
+                                               return;
+                                       }
+                               }
+                               
+                               return mpFormatEmpty.call(this, e);
+                       }).bind(this);
+                       
                        require(['Core', 'Environment'], (function (Core, Environment) {
                                if (Environment.platform() !== 'desktop') {
                                        // ignore mobile devices