Browse Source

Follow up 48dcd8d159354f31fccb6b22956925ddc81b5ad4 - Fixes #3716 - Pasting in Firefox adds unwanted whitespace/line break.

Co-authored-by: Rolf Schmidt <rolf.schmidt@zammad.com>
Florian Liebe 1 year ago
parent
commit
4c0c82e50c

+ 2 - 2
app/assets/javascripts/app/lib/app_post/utils.coffee

@@ -187,14 +187,14 @@ class App.Utils
       .replace(/\n{3,20}/g, "\n\n")   # remove multiple empty lines
 
   # htmlEscapedAndLinkified = App.Utils.text2html(rawText)
-  @text2html: (ascii, useBlockElement = true) ->
+  @text2html: (ascii) ->
     ascii = @textCleanup(ascii)
     #ascii = @htmlEscape(ascii)
     ascii = @linkify(ascii)
     ascii = ascii.replace(/(\n\r|\r\n|\r)/g, "\n")
     ascii = ascii.replace(/  /g, ' &nbsp;')
 
-    if useBlockElement
+    if ascii.match(/\n/)
       ascii = '<div>' + ascii.replace(/\n/g, '</div><div>') + '</div>'
       ascii = ascii.replace(/<div><\/div>/g, '<div><br></div>')
     else

+ 1 - 1
app/assets/javascripts/app/lib/base/jquery.contenteditable.js

@@ -405,7 +405,7 @@
     if (!text) {
       return false
     }
-    htmlString = App.Utils.text2html(text, false)
+    htmlString = App.Utils.text2html(text)
 
     // check length limit
     if (!this.maxLengthOk(htmlString.length)) {

+ 3 - 3
public/assets/tests/qunit/html_utils.js

@@ -84,7 +84,7 @@ QUnit.test("text2html", assert => {
   assert.equal(result, should, source)
 
   source = "Some   Value 123"
-  should = "<div>Some &nbsp; Value 123</div>"
+  should = "<span>Some &nbsp; Value 123</span>"
   result = App.Utils.text2html(source)
   assert.equal(result, should, source)
 
@@ -3547,7 +3547,7 @@ QUnit.test('App.Utils.clipboardHtmlInsertPreperation()', assert => {
   assert.equal(App.Utils.clipboardHtmlInsertPreperation("<div><!-- some comment --> \n </div>", {}), " \n ")
   assert.equal(App.Utils.clipboardHtmlInsertPreperation('test', {}), 'test')
   assert.equal(App.Utils.clipboardHtmlInsertPreperation('<div>test</div>', {}), 'test')
-  assert.equal(App.Utils.clipboardHtmlInsertPreperation('<meta http-equiv="content-type" content="text/html; charset=utf-8">sometext', {}), '<div>sometext</div>')
+  assert.equal(App.Utils.clipboardHtmlInsertPreperation('<meta http-equiv="content-type" content="text/html; charset=utf-8">sometext', {}), '<span>sometext</span>')
   assert.equal(App.Utils.clipboardHtmlInsertPreperation('<div><b>test</b> 123</div>', { mode: 'textonly' }), 'test 123')
   assert.equal(App.Utils.clipboardHtmlInsertPreperation('<div><b>test</b><br> 123</div>', { mode: 'textonly' }), 'test 123')
   assert.equal(App.Utils.clipboardHtmlInsertPreperation('<div><b>test</b><br> 123</div>', { mode: 'textonly', multiline: true }), 'test<br> 123')
@@ -3597,4 +3597,4 @@ QUnit.test("#buildEmailAddress", assert => {
     App.Utils.buildEmailAddress('Somebody @ "Company"', 'some.body@example.com'),
     '"Somebody @ \\"Company\\"" <some.body@example.com>'
   )
-})
+})