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

Fix for ctrl+c on examples copies the whole text, not just the selection #73

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions app/components/CodeSnippet/CodeSnippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,13 @@ export default function CodeSnippet({
return <span className={styles.inlineCode}>{children}</span>;
}
if (children[children.length - 1] === "\n") children = children.slice(0, -1);
// remove the last \n from children
Copy link
Member

Choose a reason for hiding this comment

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

Why did we remove this comment? Please keep as it is.


if (highlightLineStart && !highlightLineEnd) {
highlightLineEnd = highlightLineStart;
}

return (
<div
className={styles.codeSnippetContainer}
onCopy={(e) => {
e.preventDefault();
e.clipboardData.setData("text/plain", children);
}}
>
Comment on lines -41 to -47
Copy link
Member

Choose a reason for hiding this comment

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

Yes, it works! but have you seen the pasted code after this change? The code is not formatted correctly. It looks something like the below image
image

We also need to keep the code formatted as it is in the codeblock. This formatting issue is primarily from the react-syntax-highlighter library. You can look online and find out how other projects are using this library and find some solution for the issue.

<div className={styles.codeSnippetContainer}>
<div
className={styles.copyButton}
onClick={() => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"framer-motion": "^11.1.9",
"geist": "^1.3.0",
"gray-matter": "^4.0.3",
"my-app": "file:",
Copy link
Member

Choose a reason for hiding this comment

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

How is this change relevant?

"next": "^14.2.5",
"next-mdx-remote": "^4.4.1",
"prettier": "^3.3.3",
Expand Down