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: avoid including line numbers when copying the code #18725

Merged
merged 10 commits into from
Aug 23, 2022

Conversation

donotlb
Copy link
Contributor

@donotlb donotlb commented Jul 16, 2022

Issue: #18629

What I did

Removed the onCopyCapture event listener from the container element of ReactSyntaxHighlighter.

How to test

Start the html-kitchen-sink example, then open the Story addon panel of Button.Primary story, after that, select and copy (ctrl+c) the source code, and finally paste it somewhere.

@nx-cloud
Copy link

nx-cloud bot commented Jul 16, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit f711a09. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@yannbf
Copy link
Member

yannbf commented Jul 18, 2022

Hey @donotlb thank you so much for your contribution!

@ndelangen could you take a quick look at this? Thanks!

@donotlb
Copy link
Contributor Author

donotlb commented Jul 23, 2022

I did more tests, and found that react-syntax-highlighter itself has a few problems, the copy-paste behavior is different in different browsers when showLineNumbers is turned on.

We can visit here and test it with different browsers (remember to tick the “Show line numbers” checkbox)

I found a simple workaround to make the copy-paste behavior more consistent across browsers: use a custom renderer to process span.linenumber element in each line of code, and use a pseudo element to display line numbers.

How to test

  1. yarn start
  2. open the Basics / SyntaxHighlighter / showlinenumbers story
  3. test the copy-paste behavior in Chrome/Safari/Firefox

# Conflicts:
#	code/lib/components/src/syntaxhighlighter/syntaxhighlighter.tsx
@donotlb
Copy link
Contributor Author

donotlb commented Aug 5, 2022

Hi @ndelangen, thanks for your review, are there plans to merge this PR ?

@wangshijun
Copy link

When will this feature be included in the new release? It's really annoying to have line numbers copied.

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

Successfully merging this pull request may close these issues.

4 participants