Skip to content

Commit

Permalink
Make sure not to use lookbehind as older browsers don't support it
Browse files Browse the repository at this point in the history
  • Loading branch information
jassmith committed Dec 1, 2023
1 parent de0ab97 commit 82beb13
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
7 changes: 2 additions & 5 deletions packages/core/src/data-editor/copy-paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,7 @@ function formatHtmlTextContent(text: string): string {
// 1. Replacing tabs with four spaces for consistency. Also google sheets disallows any tabs.
// 2. Wrapping each space with a span element to prevent them from being collapsed or ignored during the
// paste operation
return text
.replace(/\t/g, " ")
.replace(/\t/g, " ")
.replace(/(?<=\s) | (?=\s)/g, "<span> </span>");
return text.replace(/\t/g, " ").replace(/ {2,}/g, match => "<span> </span>".repeat(match.length));
}

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

current?.push({
Expand Down
21 changes: 21 additions & 0 deletions packages/core/test/copy-paste.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@ describe("copy-paste", () => {
expect(result.textHtml).toContain('<td gdg-raw-value="Hello" gdg-format="string">Display Hello</td>');
});

test("Simple text cell with multiple spaces", () => {
const cells: GridCell[][] = [
[
{
kind: GridCellKind.Text,
data: "Hello",
allowOverlay: true,
displayData: "Display Hello",
},
],
];
const columnIndexes = [0];

const result = getCopyBufferContents(cells, columnIndexes);

expect(result.textPlain).toBe("Display Hello");
expect(result.textHtml).toContain(
'<td gdg-raw-value="Hello" gdg-format="string">Display<span> </span><span> </span>Hello</td>'
);
});

test("Simple text cell with special chars", () => {
const cells: GridCell[][] = [
[
Expand Down

0 comments on commit 82beb13

Please sign in to comment.