Convert bogus newlines in pasted text in Firefox
authorAlexander Ebert <ebert@woltlab.com>
Mon, 4 Feb 2019 12:10:54 +0000 (13:10 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 4 Feb 2019 12:10:54 +0000 (13:10 +0100)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js

index 775a4365ad297d9e878972ff96a9e07244a9402d..02f29c8ed188fdd583b8a3a3c3d8b5ab5a971e2c 100644 (file)
@@ -90,6 +90,16 @@ $.Redactor.prototype.WoltLabClean = function() {
                                        }
                                });
                                
+                               // Firefox inserts bogus linebreaks instead of spaces at the end of spans, if there is an adjacent span.
+                               elBySelAll('span', div, function (span) {
+                                       if (span.childNodes.length > 0) {
+                                               var lastNode = span.childNodes[span.childNodes.length - 1];
+                                               if (lastNode.nodeType === Node.TEXT_NODE && lastNode.textContent.match(/\n$/)) {
+                                                       lastNode.textContent = lastNode.textContent.replace(/\n+$/, (span.parentNode.lastChild === span ? '' : ' '));
+                                               }
+                                       }
+                               });
+                               
                                html = div.innerHTML;
                                
                                html = html.replace(/<p>\u200B<\/p>/g, '<p><br></p>');