Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onPaste does not work correctly for Excel modified data after 5.3.2 #916

Open
tb-viktor opened this issue Mar 11, 2024 · 5 comments
Open

Comments

@tb-viktor
Copy link

tb-viktor commented Mar 11, 2024

Hello,

We've encountered a regression after updating from version 5.3.1-alpha1 to latest version of the library - onPaste is no longer parsing modified table data that is copied from desktop Excel correctly if a custom onPaste function is used.

This can be easily checked by doing:

onPaste={(target, values) => {
  console.log(target.values);
  return false;
}}

And copying multi-cell data from the glide table to Excel, modifying it and pasting it back (gif below).

What is returned in values are the original values of the cells instead of the new data that has been copied from Excel.

I've done some debugging and it seems like version 5.3.2 already introduced the breaking change.

When pasted into notepad it shows the correct new values, but when pasted into the table it pastes the original values even if the table was since reloaded or cleared. Very confusing, it's like there's invisible data that gets copied which is equal to the original values?

@jassmith could you take a look?

@tb-viktor
Copy link
Author

tb-viktor commented Mar 11, 2024

To reproduce you have to:

  1. Enter data similar to screenshotted above into glide table.
  2. Select the data and copy it.
  3. Paste it into Excel.
  4. Change the number values in Excel and copy again.
  5. Paste into glide table.

Gif to illustrate:
glide-table-excel-copy2

At the last step we paste the data back into glide, the onPaste values are still the unchanged data for some reason.

@tb-viktor tb-viktor changed the title onPaste does not work correctly for Excel sourced data onPaste does not work correctly for Excel modified data Mar 13, 2024
@tb-viktor tb-viktor changed the title onPaste does not work correctly for Excel modified data onPaste does not work correctly for Excel modified data after 5.3.2 Mar 13, 2024
@tb-viktor
Copy link
Author

tb-viktor commented Apr 15, 2024

I've investigated this further and it seems that desktop Excel adds \r\n at the end of the copied string which seems to cause the paste to not apply:

image

All of these are e.clipboardData.getData('Text') (values not important). The top one is from desktop Excel, second one is the data copied from glide, and last one is web Excel.

@BrianHung
Copy link
Collaborator

BrianHung commented Jun 1, 2024

Does getting rid of the carriage return work? If so, we can just normalize the data .replace(/\r\n?/g, "\n"). Saw something similar with ProseMirror/prosemirror#1138

We could also maybe just strip trailing carriage return + new lines. Can you try patching this area with that fix and seeing if it works for you?

if (onPaste === undefined) {
const cellData = getMangledCellContent(target);
const rawValue = text ?? data?.map(r => r.map(cb => cb.rawValue).join("\t")).join("\t") ?? "";
const newVal = pasteToCell(cellData, target, rawValue, undefined);
if (newVal !== undefined) {
editList.push(newVal);
}
break;
}
if (data === undefined) {
if (text === undefined) return;
data = unquote(text);
}

@BrianHung
Copy link
Collaborator

Tried reproducing with the desktop Excel app on MacOS; might be an OS thing but the onPasteInternal logic reads from navigator.clipboard instead of e.clipboardData.

@tb-viktor
Copy link
Author

@BrianHung Thanks for looking into this! I am on Windows, and most of our clients are too, so maybe that makes a difference in what gets copied? I tried to get the repository running locally to test it, but it's throwing a bunch of errors.

I'll try to explain and show in more detail. In the gifs below I have two things in the console:

  1. DataEditor's onPaste: (_, values) => console.log('onPaste values:', values);
  2. container div onPaste={(e) => console.log('Event data:', JSON.stringify(e.clipboardData?.getData('Text')))} to show the raw text data

First weird thing, as above, is what happens if you type in some numbers into Glide and then copy them to Desktop Excel, modify them and copy them back. The numbers are unchanged in DataGrid's onPaste, but the raw text data shows the change.

excel-glide-bug-p1

Second even weirder thing is what happens when add some more rows of values in Excel. The first row is again unchanged, while the others are read properly. Even when copying multiple times in different positions, that first row still is "sticky" and does not update values, even though the raw text data is correct.

excel-glide-bug-p2

This makes no sense to me, it's like there's some sort of information in this first copied row that tells glide not to update it, but there is nothing like that in the raw data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants