Improved handling of empty `<td>` in Firefox
authorAlexander Ebert <ebert@woltlab.com>
Sun, 15 Jan 2017 17:10:50 +0000 (18:10 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 15 Jan 2017 17:10:50 +0000 (18:10 +0100)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabKeydown.js

index b794e1d111592cad5b10169d12f28ba8fa09bb12..cc9eb262f5abd970c9eaa150573978187de7e112 100644 (file)
@@ -30,6 +30,14 @@ $.Redactor.prototype.WoltLabClean = function() {
                                        }
                                });
                                
+                               // each `<td>` must at least contain \u200B, otherwise
+                               // Firefox will be unable to place the caret inside
+                               elBySelAll('td', div, function (td) {
+                                       if (td.childNodes.length === 0) {
+                                               td.innerHTML = '\u200B';
+                                       }
+                               });
+                               
                                html = div.innerHTML;
                                
                                return html;
index 987e46f49006df3684665562a3c9d67bc0379b9b..59e4138e460a157707168329d2ab00f8b9f87147 100644 (file)
@@ -369,7 +369,24 @@ $.Redactor.prototype.WoltLabKeydown = function() {
                        var firefoxHandleBackspace = (function(e) {
                                var parent;
                                var block = this.selection.block();
-                               if (block.nodeName.indexOf('-') !== -1 && isEmpty(block)) {
+                               if (!block) {
+                                       return;
+                               }
+                               
+                               if (block.nodeName === 'TD') {
+                                       var html = block.innerHTML;
+                                       if (html === '\u200B') {
+                                               // backspacing the `\u200B` will break Firefox
+                                               e.preventDefault();
+                                       }
+                                       else if (html === '') {
+                                               // Firefox already broke itself, try to recover
+                                               e.preventDefault();
+                                               
+                                               block.innerHTML = '\u200B';
+                                       }
+                               }
+                               else if (block.nodeName.indexOf('-') !== -1 && isEmpty(block)) {
                                        // backspacing an entire block
                                        parent = block.parentNode;
                                        parent.insertBefore(this.marker.get(), block.nextSibling);