Skip to content

Commit

Permalink
fix: ctrl+c on examples copies the whole text (#74)
Browse files Browse the repository at this point in the history
* fixes to ctrl+c issue on code snippet

* fixes to ctrl+c issue and  line highlighting

* fixes to ctrl+c issue and  line highlighting

* line highlighting changes

* Update app/components/CodeSnippet/CodeSnippet.tsx

* Update app/components/CodeSnippet/CodeSnippet.tsx

---------

Co-authored-by: Zeel Rajodiya <[email protected]>
  • Loading branch information
AkshataABhat and JeelRajodiya authored Sep 22, 2024
1 parent 6c6829c commit 9c7836f
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions app/components/CodeSnippet/CodeSnippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
import SyntaxHighlighter from "react-syntax-highlighter";
import {
nightOwl,
atelierCaveLight,
arduinoLight,
atelierEstuaryLight,
} from "react-syntax-highlighter/dist/esm/styles/hljs";
import styles from "./CodeSnippet.module.css";
import { CSSProperties, useState } from "react";
Expand Down Expand Up @@ -38,13 +36,7 @@ export default function CodeSnippet({
}

return (
<div
className={styles.codeSnippetContainer}
onCopy={(e) => {
e.preventDefault();
e.clipboardData.setData("text/plain", children);
}}
>
<div className={styles.codeSnippetContainer}>
<div
className={styles.copyButton}
onClick={() => {
Expand Down Expand Up @@ -73,7 +65,7 @@ export default function CodeSnippet({
paddingBlock: "10px",
}}
wrapLines={true}
wrapLongLines={true}
wrapLongLines={false}
lineNumberStyle={{
color: "hsl(var(--text) / 0.6)",
paddingRight: "12px",
Expand All @@ -82,10 +74,12 @@ export default function CodeSnippet({
startingLineNumber={startingLineNumber}
lineProps={(lineNumber) => {
let style: CSSProperties = {
opacity: colorMode === "dark" ? 0.9 : 1,
display: "block",
paddingRight: "16px",
paddingLeft: "4px",
opacity: colorMode === "dark" ? 0.9 : 1,
};

if (
highlightLineStart &&
highlightLineEnd &&
Expand All @@ -101,6 +95,7 @@ export default function CodeSnippet({
}`,
};
}

return { style };
}}
>
Expand Down

0 comments on commit 9c7836f

Please sign in to comment.