Skip to content

Commit 82beb13

Browse files
committed
Make sure not to use lookbehind as older browsers don't support it
1 parent de0ab97 commit 82beb13

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

packages/core/src/data-editor/copy-paste.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,7 @@ function formatHtmlTextContent(text: string): string {
149149
// 1. Replacing tabs with four spaces for consistency. Also google sheets disallows any tabs.
150150
// 2. Wrapping each space with a span element to prevent them from being collapsed or ignored during the
151151
// paste operation
152-
return text
153-
.replace(/\t/g, " ")
154-
.replace(/\t/g, " ")
155-
.replace(/(?<=\s) | (?=\s)/g, "<span> </span>");
152+
return text.replace(/\t/g, " ").replace(/ {2,}/g, match => "<span> </span>".repeat(match.length));
156153
}
157154

158155
function formatHtmlAttributeContent(attrText: string): string {
@@ -294,7 +291,7 @@ export function decodeHTML(html: string): CopyBuffer | undefined {
294291
let textContent = clone.textContent ?? "";
295292
if (isAppleNumbers) {
296293
// replace any newline not preceded by a newline
297-
textContent = textContent.replace(/(?<!\n)\n/g, "");
294+
textContent = textContent.replace(/\n(?!\n)/g, "");
298295
}
299296

300297
current?.push({

packages/core/test/copy-paste.test.ts

+21
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,27 @@ describe("copy-paste", () => {
8282
expect(result.textHtml).toContain('<td gdg-raw-value="Hello" gdg-format="string">Display Hello</td>');
8383
});
8484

85+
test("Simple text cell with multiple spaces", () => {
86+
const cells: GridCell[][] = [
87+
[
88+
{
89+
kind: GridCellKind.Text,
90+
data: "Hello",
91+
allowOverlay: true,
92+
displayData: "Display Hello",
93+
},
94+
],
95+
];
96+
const columnIndexes = [0];
97+
98+
const result = getCopyBufferContents(cells, columnIndexes);
99+
100+
expect(result.textPlain).toBe("Display Hello");
101+
expect(result.textHtml).toContain(
102+
'<td gdg-raw-value="Hello" gdg-format="string">Display<span> </span><span> </span>Hello</td>'
103+
);
104+
});
105+
85106
test("Simple text cell with special chars", () => {
86107
const cells: GridCell[][] = [
87108
[

0 commit comments

Comments
 (0)