Caret could not be set into empty but formatted list item
authorAlexander Ebert <ebert@woltlab.com>
Tue, 20 Jan 2015 18:26:37 +0000 (19:26 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 20 Jan 2015 18:26:37 +0000 (19:26 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wmonkeypatch.js

index 6d0fcdfa4afc757cb4fd01b695acadc07067804e..9a24ff5ed412b4af69cb4c2b390dfd0640ca30db 100644 (file)
@@ -171,6 +171,34 @@ RedactorPlugins.wmonkeypatch = function() {
                                        
                                        return false;
                                }
+                               else if (event.target.tagName === 'LI') {
+                                       // work-around for #1942
+                                       var $range = (window.getSelection().rangeCount) ? window.getSelection().getRangeAt(0) : null;
+                                       var $caretInsideList = false;
+                                       if ($range !== null) {
+                                               if (!$range.collapsed) {
+                                                       return;
+                                               }
+                                               
+                                               var $current = $range.startContainer;
+                                               while ($current !== null && $current !== this.$editor[0]) {
+                                                       if ($current.tagName === 'LI') {
+                                                               $caretInsideList = true;
+                                                               break;
+                                                       }
+                                                       
+                                                       $current = $current.parentElement;
+                                               }
+                                       }
+                                       
+                                       if (!$caretInsideList || $range === null) {
+                                               var $node = document.createTextNode('\u200b');
+                                               var $firstChild = event.target.children[0];
+                                               $firstChild.appendChild($node);
+                                               
+                                               this.caret.setEnd($firstChild);
+                                       }
+                               }
                        }).bind(this));
                },