FIX: paste table with multiline cell (#12194)

When a cell is multiline, it is wrapped with quotes. It can be used to determine if it is a "real" new line or not.

Meta: https://meta.discourse.org/t/pasting-google-sheets-table-with-a-cell-that-contain-a-line-break/173106
This commit is contained in:
Krzysztof Kotlarek 2021-02-25 09:39:54 +11:00 committed by GitHub
parent 362dd798ae
commit 57bfc398d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -883,7 +883,19 @@ export default Component.extend({
text = text.substring(0, text.length - 1); 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) { if (rows.length > 1) {
const columns = rows.map((r) => r.split("\t").length); const columns = rows.map((r) => r.split("\t").length);

View File

@ -721,6 +721,11 @@ third line`
let element = queryAll(".d-editor")[0]; let element = queryAll(".d-editor")[0];
await paste(element, "\ta\tb\n1\t2\t3"); await paste(element, "\ta\tb\n1\t2\t3");
assert.equal(this.value, "||a|b|\n|---|---|---|\n|1|2|3|\n"); 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");
}, },
}); });