Skip to content

Commit

Permalink
keyboard shortcut copies highlighted code only
Browse files Browse the repository at this point in the history
  • Loading branch information
melindali255 committed Jul 15, 2021
1 parent 49e67a0 commit ae5436a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/components/src/syntaxhighlighter/syntaxhighlighter.tsx
Expand Up @@ -163,7 +163,12 @@ export const SyntaxHighlighter: FunctionComponent<Props> = ({
const onClick = (e: MouseEvent<HTMLButtonElement> | ClipboardEvent<HTMLDivElement>) => {
e.preventDefault();

copyToClipboard(highlightableCode)
const textToCopy =
e.type !== 'click' && globalWindow.getSelection().toString() !== ''
? globalWindow.getSelection().toString()
: highlightableCode;

copyToClipboard(textToCopy)
.then(() => {
setCopied(true);
globalWindow.setTimeout(() => setCopied(false), 1500);
Expand Down

0 comments on commit ae5436a

Please sign in to comment.