Skip to content

Commit

Permalink
fix: copying of large data (#588)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfig committed Jul 5, 2023
1 parent 8a3c4ad commit 3698dd4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/debugFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
export const debug = process.env.REACT_APP_DEBUG === '1' ? true : false;

// skip python load (used to speed up debugging)
export const debugSkipPythonLoad = debug && true;
export const debugSkipPythonLoad = debug && false;

// ------------------
// Debug footer marks
Expand Down
22 changes: 9 additions & 13 deletions src/grid/actions/clipboard/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ const pasteFromTextOrHtml = async (sheet_controller: SheetController, pasteToCel
}
}
return false; // unsuccessful
} catch {
} catch (e) {
console.warn(e);
return false; // unsuccessful
}
};
Expand Down Expand Up @@ -196,7 +197,7 @@ const pasteFromText = async (sheet_controller: SheetController, pasteToCell: Coo

return true; // unsuccessful
} catch (e) {
console.log(e);
console.warn(e);
return false; // unsuccessful
}
};
Expand Down Expand Up @@ -274,6 +275,11 @@ export const generateClipboardStrings = (sheet_controller: SheetController, cell
};
};

// from https://stackoverflow.com/a/49124600
function btoaFromCharCode(data: Uint8Array): string {
return btoa(data.reduce((data, byte) => data + String.fromCharCode(byte), ''));
}

export const copyToClipboard = async (sheet_controller: SheetController, cell0: Coordinate, cell1: Coordinate) => {
// write selected cells to clipboard
const { plainTextClipboardString, htmlClipboardString, quadraticClipboardString } = generateClipboardStrings(
Expand All @@ -282,15 +288,6 @@ export const copyToClipboard = async (sheet_controller: SheetController, cell0:
cell1
);

// const quadraticString = btoa(
// JSON.stringify({
// type: CLIPBOARD_FORMAT_VERSION,
// data: quadraticClipboardString,
// cell0,
// cell1,
// })
// );

const encoder = new TextEncoder();
const quadraticData = encoder.encode(
JSON.stringify({
Expand All @@ -300,8 +297,7 @@ export const copyToClipboard = async (sheet_controller: SheetController, cell0:
cell1,
})
);
const quadraticString = btoa(String.fromCharCode(...quadraticData));

const quadraticString = btoaFromCharCode(quadraticData);
const clipboardHTMLString = `<span data-metadata="<--(quadratic)${quadraticString}(/quadratic)-->"></span>${htmlClipboardString}`;

// https://github.com/tldraw/tldraw/blob/a85e80961dd6f99ccc717749993e10fa5066bc4d/packages/tldraw/src/state/TldrawApp.ts#L2189
Expand Down

1 comment on commit 3698dd4

@vercel
Copy link

@vercel vercel bot commented on 3698dd4 Jul 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

quadratic – ./

quadratic-quadratic.vercel.app
quadratic-git-main-quadratic.vercel.app
quadratic-nu.vercel.app

Please sign in to comment.