Fixed pasting of single-line content in Firefox
authorAlexander Ebert <ebert@woltlab.com>
Tue, 10 Oct 2017 17:02:46 +0000 (19:02 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 10 Oct 2017 17:02:46 +0000 (19:02 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabPaste.js

index 55f876316fc430f21d45372c35baac2e536f85b2..a92236276e7b3b21444557d4fce00195f0289027 100644 (file)
@@ -36,15 +36,23 @@ $.Redactor.prototype.WoltLabPaste = function() {
                                else if (this.detect.isFirefox()) {
                                        var types = e.originalEvent.clipboardData.types;
                                        if (types.length === 1 && types[0] === 'text/plain') {
-                                               var tmp = e.originalEvent.clipboardData.getData('text/plain');
+                                               var tmp = WCF.String.escapeHTML(e.originalEvent.clipboardData.getData('text/plain'));
                                                
                                                firefoxPlainText = '';
-                                               tmp.split("\n").forEach(function(line) {
-                                                       line = line.trim();
-                                                       if (line === '') line = '<br>';
-                                                       
-                                                       firefoxPlainText += '<p>' + line + '</p>';
-                                               });
+                                               var lines = tmp.split("\n");
+                                               if (lines.length === 1) {
+                                                       // paste single-line content as real plain text
+                                                       firefoxPlainText = tmp;
+                                               }
+                                               else {
+                                                       // plain newline characters do not work out well, mimic HTML instead
+                                                       lines.forEach(function (line) {
+                                                               line = line.trim();
+                                                               if (line === '') line = '<br>';
+                                                               
+                                                               firefoxPlainText += '<p>' + line + '</p>';
+                                                       });
+                                               }
                                        }
                                }