Skip to content

A platform for community discussion. Free, open, simple.

FIX: paste table with multiline cell (#12194)

Krzysztof Kotlarek57bfc398d444
diff --git a/app/assets/javascripts/discourse/app/components/d-editor.js b/app/assets/javascripts/discourse/app/components/d-editor.js
index 6ad50517b1f..a05cb731363 100644
--- a/app/assets/javascripts/discourse/app/components/d-editor.js
+++ b/app/assets/javascripts/discourse/app/components/d-editor.js
@@ -883,7 +883,19 @@ export default Component.extend({
text = text.substring(0, text.length - 1);
}
- let rows = text.split("\n");
+ text = text.split("");
+ let cell = false;
+ text.forEach((char, index) => {
+ if (char === "\n" && cell) {
+ text[index] = "\r";
+ }
+ if (char === '"') {
+ text[index] = "";
+ cell = !cell;
+ }
+ });
+
+ let rows = text.join("").replace(/\r/g, "<br>").split("\n");
if (rows.length > 1) {
const columns = rows.map((r) => r.split("\t").length);
diff --git a/app/assets/javascripts/discourse/tests/integration/components/d-editor-test.js b/app/assets/javascripts/discourse/tests/integration/components/d-editor-test.js
index 1f82ba0e164..33fe369718a 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/d-editor-test.js
+++ b/app/assets/javascripts/discourse/tests/integration/components/d-editor-test.js
@@ -721,6 +721,11 @@ third line`
let element = queryAll(".d-editor")[0];
await paste(element, "\ta\tb\n1\t2\t3");
assert.equal(this.value, "||a|b|\n|---|---|---|\n|1|2|3|\n");
+
+ this.set("value", "");
+
+ await paste(element, '\ta\tb\n1\t"2\n2.5"\t3');
+ assert.equal(this.value, "||a|b|\n|---|---|---|\n|1|2<br>2.5|3|\n");
},
});