Workaround for malformed nested lists in Chromium browsers
authorAlexander Ebert <ebert@woltlab.com>
Sat, 22 Feb 2020 11:29:49 +0000 (12:29 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 22 Feb 2020 11:29:49 +0000 (12:29 +0100)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeyup.js

index 55e18f5e7694fe6d879b5d56056f6e6211f9e31d..2468d00e93386779bf0e96fa45337e35bce35748 100644 (file)
@@ -43,6 +43,17 @@ $.Redactor.prototype.WoltLabKeyup = function() {
                                }
                        }
                        
+                       // Chromium browsers will cripple a nested list when exiting with [Enter], causing lists
+                       // to become siblings of the previously parent <li>. This leads to situations where the
+                       // code `<li><ul /></li>` ends up as `<li /><ul />` (HTML shortened for brevity).
+                       var listItem = elClosest(selection.anchorNode, 'li');
+                       if (listItem !== null && editor.contains(listItem)) {
+                               var previousList = listItem.previousElementSibling;
+                               if (previousList !== null && (previousList.nodeName === 'OL' || previousList.nodeName === 'UL')) {
+                                       previousList.previousElementSibling.appendChild(previousList);
+                               }
+                       }
+                       
                        var node = selection.anchorNode;
                        while (node.parentNode) {
                                if (node.parentNode === editor) {