-
Notifications
You must be signed in to change notification settings - Fork 25
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: prevent nbsp characters from being manually copied #2455
Conversation
The latest updates on your projects. Learn more about Vercel for Git βοΈ
|
π¦ Next.js Bundle AnalysisThis analysis was generated by the next.js bundle analysis action π€ This PR introduced no changes to the javascript bundle π |
Thanks for tackling this - such a β¨ FUN β¨ issue ahah! π Tested as described, and am indeed no longer seeing those NBSP characters, nor when using the
Maybe this is something we can live with... I did a bit more digging though, and found that selecting and copying the text didn't seem to yield those weird whitespace characters in the first place (in my experience, at least). But, using the 2024-05-17-weird-whitespace-chars-in-copy-button-use.mp4And then in VSCode: 2024-05-17-invisible-chars-in-vscode-from-copy-button-only.mp4As well it seems in some browsers (FireFox is where I found this), selecting and copying the text yields a pasted value with no newlines at all (upstream, and also in this PR, shown with preview link of this PR): 2024-05-17-firefox-select-and-copy-missing-whitespace.mp4Looking back on the original report in Slack I think this lines up... We kind of have two separate but somewhat related problems:
Which is all to say... I think we may need a separate fix for the The "good news" (well kinda maybe?) is that we don't have to contend with the "select" and "copy button" issues being super-intertwined, so we don't have to try to solve both problems at once (i think this might've been one of the reasons we introduced ANYWAYS... point being, for the |
This is actually from the Vercel toolbar! |
@dstaley ahah oh man, the pink highlighting makes so much more sense now π€¦ Edited the comment to reflect that! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looked at this again, definitely fixes the "weird whitespace in Copy button" issue so seems like a great improvement π (Apologies for the wall of text earlier, went on quite the tangent there! πββοΈ)
π Relevant links
ποΈ What
This PR switches blank lines in our CodeBlocks to use a CSS pseudo element, which won't be copied when the user manually selects content to copy.
π€· Why
Due to the way we split lines, empty lines aren't properly retained. We need to manually insert those blank lines, which requires that we give them some content so they take up space. Previously, we used the
nbsp;
character, but this creates issues when code is copied and pasted, since some languages don't allow this specific character.π οΈ How
This PR switches the approach somewhat, by targeting empty lines via a specific CSS class. This class uses the
:after
pseudo element to render a space character, which isn't copied to the clipboard when a user selects code.Unfortunately, since the blank lines have no content (not even a line terminating character), blank lines are not preserved when copied manually (they are when using the copy button). We can iterate and fix this later, but right now the important thing is preventing unsupported characters from ending up in our users' code.
πΈ Design Screenshots
π§ͺ Testing
`
`
.includes('\xa0')
false
(meaning the string does not contain the non-breaking space character).