Work-around for the caret position in nested lists in Firefox
authorAlexander Ebert <ebert@woltlab.com>
Tue, 13 Feb 2018 13:10:45 +0000 (14:10 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 13 Feb 2018 13:10:45 +0000 (14:10 +0100)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeyup.js

index 14e913fe4a14bd5fcdccaaa8b8df9c5ffb1ff26f..55e18f5e7694fe6d879b5d56056f6e6211f9e31d 100644 (file)
@@ -14,8 +14,36 @@ $.Redactor.prototype.WoltLabKeyup = function() {
                        var editor = this.$editor[0];
                        
                        var selection = window.getSelection();
-                       var node = selection.anchorNode;
                        var parent = null;
+                       
+                       if (this.detect.isFirefox()) {
+                               var anchorNode = selection.anchorNode;
+                               if (anchorNode.nodeType === Node.TEXT_NODE && selection.anchorOffset === 0) {
+                                       parent = anchorNode.parentNode;
+                                       if (parent.childNodes[0] === anchorNode) {
+                                               anchorNode = anchorNode.parentNode;
+                                       }
+                               }
+                               
+                               if (anchorNode.nodeName === 'LI') {
+                                       // check if this is a nested list
+                                       var list = anchorNode.parentNode;
+                                       parent = list.parentNode;
+                                       
+                                       // Firefox does not handle nested lists well, yielding untargetable list items
+                                       // see https://bugzilla.mozilla.org/show_bug.cgi?id=1428073
+                                       if (parent.nodeName === 'LI' && list.previousSibling === null) {
+                                               parent.insertBefore(this.marker.get(), list);
+                                               parent.insertBefore(elCreate('br'), list);
+                                               
+                                               this.selection.restore();
+                                               
+                                               return;
+                                       }
+                               }
+                       }
+                       
+                       var node = selection.anchorNode;
                        while (node.parentNode) {
                                if (node.parentNode === editor) {
                                        parent = node;