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

Docs: Copy functionality is picking up extra line breaks #9889

Open
brantgurga opened this issue Dec 6, 2024 · 3 comments
Open

Docs: Copy functionality is picking up extra line breaks #9889

brantgurga opened this issue Dec 6, 2024 · 3 comments
Assignees

Comments

@brantgurga
Copy link

Bug Report

As illustrated in Justin Garrison's live stream recently https://www.youtube.com/watch?v=xenP7jkecWA the copy functionality in the docs is picking up extra line breaks.

Description

I looked into it and I think the culprit is the copyCodeToClipboard function in clipboard.js. It is grabbing innerText which preserves the source code/DOM formatting. I think textContent is what you want instead based on some preliminary in-browser tweaking/testing and reading up on the different between those properties.

@brantgurga
Copy link
Author

@rothgar I tested this a little in the browser setting a breakpoint at the start of the copyCodeToClipboard function so the browser console had the same scope and then I ran the line with innerText manually replacing innerText with textContent and the line breaking looked more as expected so you might try that and see if that looks like the right thing to be copying.

@rothgar rothgar self-assigned this Dec 7, 2024
@rothgar
Copy link
Member

rothgar commented Dec 7, 2024

Thanks for looking. I'm trying to figure out why we have a custom copy to clipboard function instead of using the one built in to docsy. I'm going to try removing it and see if I can figure out what (if anything) we lose.

@brantgurga
Copy link
Author

brantgurga commented Dec 7, 2024

@rothgar The custom implementation in this repository is from March 29, 2022 (6665e0f). The copy function in Docsy appears to have been added October 6, 2022 (google/docsy@de7048f). So I'd say it's a custom implementation since it just wasn't in Docsy at the time. If the Docsy version works acceptably, I certainly agree that's the way to go and drop the custom implementation.

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

No branches or pull requests

2 participants