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

Problem with "copy" button functionality on EuiCodeBlock when lines end in a "?". #6585

Closed
btychon opened this issue Feb 9, 2023 · 4 comments · Fixed by #6794
Closed

Problem with "copy" button functionality on EuiCodeBlock when lines end in a "?". #6585

btychon opened this issue Feb 9, 2023 · 4 comments · Fixed by #6794
Assignees
Labels
bug low hanging fruit An issue, often a bug, that is lower effort and clearly ought to be fixed

Comments

@btychon
Copy link

btychon commented Feb 9, 2023

We use the EuiCodeBlock to display read-only scripts. There are rare cases when lines of code end in a question mark. The isCopyable attribute is applied to the component and our users press the button in the UI to copy the script contents to their clipboard. For some weird reason, when the clipboard contents are pasted into a generic text editor the "question marks" go missing... but only if they're located at the end of a line.

Adding a blank space to lines ending with "$" is a kludgy workaround.

For example:

  • Script content: a? Copy button action places a on the clipboard. <-- BUG
  • Script content: a?a Copy button action places a?a on the clipboard.
  • Script content: a? Copy button action places a? on the clipboard.

``

@JasonStoltz
Copy link
Member

@btychon Do you think you could reproduce this in Code Sandbox? It would help us a lot to validate and debug this issue. You can get a link to a pre-populated Code Sandbox from the Demo JS tab within our docs: https://elastic.github.io/eui/#/editors-syntax/code.

Thank you!

@btychon
Copy link
Author

btychon commented Feb 10, 2023

I got the link to the sandbox for the EuiCodeBlock but something is broken???
https://codesandbox.io/s/4pybz2?file=/demo.js

@1Copenut
Copy link
Contributor

@btychon Thank you for the follow up comment reporting the bug in CodeSandbox. I'm working on a fix PR for that secondary item now.

In the meantime, if you remove the second import React from 'react'; statement on line 3, and change line 5 to something like the following, it should render properly:

/* Line 5 of CodeSandbox example */

const jsCode = `/* I'm an example of JS */
const myObj = {
  key1: 1,
  key2: 'string value'
  key3: ['val', 'val2', 'val3']
};`;

@btychon
Copy link
Author

btychon commented Feb 14, 2023

Here's an example of the bug. Just hit the copy button in the EuiCodeBlock and try to paste into a text editor.
https://codesandbox.io/s/elegant-darwin-h2epdl?file=/demo.js

@cee-chen cee-chen added the bug label Mar 20, 2023
@cee-chen cee-chen added the low hanging fruit An issue, often a bug, that is lower effort and clearly ought to be fixed label May 8, 2023
@tkajtoch tkajtoch self-assigned this May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug low hanging fruit An issue, often a bug, that is lower effort and clearly ought to be fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants