-
Notifications
You must be signed in to change notification settings - Fork 12
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
Prevent newlines from being duplicated after copying an enhanced codeblock #248
Conversation
Thanks for opening this pull request! 🙏 |
The spec from this PR is available at https://preview.sesh.rs/previews/eecs485staff/primer-spec/248/. (Available until Mon May 08 2023.) |
if (!node) { | ||
throw new Error('node cannot be null'); | ||
} | ||
const mouseEvent = new CustomEvent(eventType); |
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.
I changed this to use CustomEvent
instead of document.createEvent
because the latter relies on Event.initEvent
, which is deprecated.
Thanks for putting this up @noah-weingarden! I’ll try to get to this over the weekend.
Actually, it’s likely for a single line of code to have child nodes since syntax highlighting is applied as span elements over specific tokens. However, I agree with you that Could you update the unit test with more nested syntax highlighting nodes from an actual rendered code block? You should be able to get this by viewing the HTML source of a Primer Spec page. |
Haha, then
I don't think that would work: the event handler for clicking the button won't be attached if I just use the raw HTML for the rendered code block. We'd have to convert the HTML code to DOM nodes and then manually call |
I'm sorry I still haven't got to this. It's on my todo list for this weekend though! |
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 after pushing the nits that I referenced in my previous comment. Thanks for putting this up @noah-weingarden!
Oh, I see what you meant now! And no problem! |
Closes #246. I wrote a test to expose this (and it's the first test for copying an enhanced codeblock in general). Unfortunately,
jsdom
doesn't implementinnerText
(see jsdom/jsdom#1245), so I had to modify the map function to usetextContent
instead. I think that should be ok in this use case since the element containing the text for a single line of code is unlikely to ever have child nodes. If not though, I probably wrote that test for nothing.