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

Feature request / question: newline at the end of the paste text #56

Closed
tzach opened this issue Jan 21, 2020 · 5 comments
Closed

Feature request / question: newline at the end of the paste text #56

tzach opened this issue Jan 21, 2020 · 5 comments

Comments

@tzach
Copy link
Contributor

tzach commented Jan 21, 2020

When pasting a copy text, an extra newline is added at the end.
On the terminal, it means an Enter command which starts executing.
Any way to remove it?

@choldgraf
Copy link
Member

Ah, that's a good point - I'd be +1 on this. I think that the fix would need to be here:

https://github.com/choldgraf/sphinx-copybutton/blob/master/sphinx_copybutton/_static/copybutton.js#L72

That is the code that grabs the text content of the cell and returns the text to be copied. You'd want to modify that to check for an empty final line and remove it

@tzach
Copy link
Contributor Author

tzach commented Jan 21, 2020

Indeed!
The following change fixes the problem:

- return textContent.join('\n')
+ return textContent.join('')

@choldgraf
Copy link
Member

Wouldn't that remove all the newlines inside the code as well? I think we only want to remove the very last newline

@tzach
Copy link
Contributor Author

tzach commented Jan 21, 2020

You are right, sorry my JS is rusty
This should do the work

return textContent.slice(0, -1).join('\n') + textContent.slice(-1);

@choldgraf
Copy link
Member

this is fixed in #58

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

Successfully merging a pull request may close this issue.

2 participants