Outdent in Firefox did not work for nested items with a trailing `<br>`
authorAlexander Ebert <ebert@woltlab.com>
Mon, 5 Feb 2018 17:38:21 +0000 (18:38 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 5 Feb 2018 17:38:21 +0000 (18:38 +0100)
See #2529

wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabIndent.js

index 5c60142e62145100e217d0cc4f7215c8893975a3..70fa8305bef44d8969715f0768ea381db3e6294c 100644 (file)
@@ -71,6 +71,21 @@ $.Redactor.prototype.WoltLabIndent = function() {
                                                marker1 = elCreate('woltlab-list-marker');
                                                $current[0].insertBefore(marker1, $current[0].firstChild);
                                                
+                                               // Firefox fails to outdent the item when it contains a trailing `<br>`
+                                               var lastELement = $current[0].lastElementChild;
+                                               if (lastELement.nodeName === 'BR') {
+                                                       // verify that there is no text after the br
+                                                       var text = '';
+                                                       var sibling = lastELement;
+                                                       while (sibling.nextSibling) {
+                                                               text += sibling.textContent;
+                                                       }
+                                                       
+                                                       if (text.replace(/\u200B/g, '').trim() === '') {
+                                                               elRemove(lastELement);
+                                                       }
+                                               }
+                                               
                                                marker2 = elCreate('woltlab-list-marker');
                                                $current[0].appendChild(marker2);