-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add copy code button to code snippets #945
Conversation
Hey @simonebortolin, thanks for submitting your PR! I'll give it a more in-depth look soon; in the meantime, could you resolve the lint errors? |
Yes of course the lint errors I wanted to solve them asap.
…On Fri, 2 Sept 2022, 07:12 Matt Wang, ***@***.***> wrote:
Hey @simonebortolin <https://github.com/simonebortolin>, thanks for
submitting your PR! I'll give it a more in-depth look soon; in the
meantime, could you resolve the lint errors?
—
Reply to this email directly, view it on GitHub
<#945 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGMZW4EODCQCRPAWELTGJXTV4GEDDANCNFSM6AAAAAAQBRPPSM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
19a9f33
to
f6a96f7
Compare
Hello everyone, I should have corrected the style to make the lint happy (I hope, I have not yet seen the status of the automatic CI/CD controls) I've also added an option to disable the copy button in the yml, I'm not sure if the logic is correct or if it's better != false for the default case management |
I will add some thoughts/information
P.S. If you look at my fork I am doing a total review of colour management and add form layouts, and I will submit them to PR as soon as they are ready, they are not ready yet and I am still creating them according to the needs of the sites where JTD is |
FYI - you can run these locally as well with
No worries, take your time! |
Hey @simonebortolin, just wanted to check - were you hoping to merge this in for the upcoming release? If so, I think there's a merge conflict / CI issues, but after those are resolved happy to give a review! |
Hi, after September 21 I will fix everything.
Now I really don't think that feature will come out in v4.0.0.
…On Thu, 15 Sept 2022, 02:16 Matt Wang, ***@***.***> wrote:
Hey @simonebortolin <https://github.com/simonebortolin>, just wanted to
check - were you hoping to merge this in for the upcoming release? If so, I
think there's a merge conflict / CI issues, but after those are resolved
happy to give a review!
—
Reply to this email directly, view it on GitHub
<#945 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGMZW4DXFYODKLAA2DQTPXDV6JTHHANCNFSM6AAAAAAQBRPPSM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
No worries, sounds good! |
I've already sketched out the fix anyway, it just needs to be finished and
committed
Simone
…On Thu, 15 Sept 2022, 20:44 Matt Wang, ***@***.***> wrote:
No worries, sounds good!
—
Reply to this email directly, view it on GitHub
<#945 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGMZW4HLE5HXCR2SSFINAWLV6NU7HANCNFSM6AAAAAAQBRPPSM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
7cca09b
to
b996426
Compare
Hello @mattxwang everything should now be complete I should have synchronised the repo, I rebased a few commits because there were so many to manage in one PR And I launched If there are other changes I will make them next week. to fix this |
@mattxwang can you try to launch the workflow? these days I am free and will fix any problems |
@mattxwang can you try again |
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.
Hey @simonebortolin, a couple of broad stroke notes:
- if you're adding a configuration option, we should add some documentation explaining how users could use it. Can you add some writing to the configuration page to explain how to use this feature?
- what's the driving use-case for customizing the timeout time? I imagine it would be relatively standardized?
the icons come from bootstrap icons, licensed by MIT, I don't think anything else needs to be added
- this is not true - if the icons are MIT licensed, we're obligated to redistribute a copy of the license (and, additionally, we should credit them)
- there are some areas of the site where the new styling you've added changes the spacing in a code block. For example, on the code page on
main
:
The same page on the deploy preview:
Note the shifted backticks/js!
Appreciate your work on this PR. I think with a bit of tidying, we'll be able to merge in no time!
done
none, but one more option is always better than less
yes, but JTD is also via MIT licence, so the licence copy is already there. I don't think anything more needs to be said, maybe I'm wrong.
done |
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.
Sorry, have been in and out - personal stuff.
none, but one more option is always better than less
Hm, I slightly disagree, since this is extra stuff we need to document and maintain. If there's no motivating use-case, can we not include this for now? It's much easier for us to add features later on, once people request it.
yes, but JTD is also via MIT licence, so the licence copy is already there. I don't think anything more needs to be said, maybe I'm wrong.
Ah, not exactly. We need to include a different license copy for each different project we use; this is because each library has its own copyright notice attached to the MIT license. For example, this repo's reads:
Copyright (c) 2016 Patrick Marsceill
Which is the original creator of the theme. In contrast, the Bootstrap Icon MIT License reads
Copyright (c) 2019-2021 The Bootstrap Authors
Light-touch changes left, but if we address those two points I'd be happy to merge this in! Apologies for how long this has taken, usually my iteration loop is tighter.
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.
Thanks @simonebortolin for implementing this feature. As a user of the theme I am very interested, so I took a look and left a couple of comments in regards to naming:
yes you are right, but @mattxwang told me to remove it @mattxwang sorry I've been full too, next week I'll make the changes |
No worries, take your time @simonebortolin! |
70b7a3f
to
cf4cb08
Compare
@mattxwang OK I'm there
I wish happy holidays to all I am so sorry for my absence |
- add icon, css, and js for the copy button on each 'code' enviroment - add yml/liquid option for disable copy button - add relative doc
cf4cb08
to
b51e943
Compare
- add icon, css, and js for the copy button on each 'code' enviroment - add yml/liquid option for disable copy button - add relative doc
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.
Thanks again @simonebortolin for taking this up, and don't apologize at all for taking a while - this is free open-source, and you're volunteering your time!
Overall I think this is pretty good to merge; I've left some minor nits in code review. I've also noticed on mobile that the clipboard gets clipped; this is me on Safari on iOS:
To be frank, I'm actually fine with merging this as-is with the mobile bug (and fixing it in a follow-up), since I think it's not breaking the feature + it's uncommon for users to copy code from a mobile device. If you can address the suggested comments, we can merge this in for the last RC of this calendar year!
Co-authored-by: Matt Wang <matt@matthewwang.me>
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.
Leaving a green check since this is technically in a mergeable state, but @simonebortolin it would be great if you could also prune the CSS properties and/or add some docs.
I'll merge this in before releasing our RC & resolve the merge conflict with #1058 (should be trivial).
@mattxwang OK then
|
@mattxwang I have added comments explaining the logic of how code.scss works bitterly unable to reduce the number, I gave the best of my knowledge to get this PR right |
No worries, thanks for taking this on!
Nope, I'll handle it since I'm authoring the other PR! |
Thanks for taking this on! Much appreciated @simonebortolin, and congrats on your first contribution! |
it was beautiful!
Thanks! come on that the second PR is already in the working |
|
||
copyButton.addEventListener('click', function () { | ||
if(timeout === null) { | ||
var code = codeBlock.querySelector('code').innerText.trim(); |
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.
This PR fixes three bugs: # first bug When revising my last PR #1086 I realised a slight bug in the code-copy PR #945 , my change to the css ignored a case. This PR is a hotfix and Before PR #945: ![image](https://user-images.githubusercontent.com/26844016/209864912-2fe8e5a9-f21e-40c7-aa0d-65050196f4ee.png) ![image](https://user-images.githubusercontent.com/26844016/209864950-c315cef1-36ee-4356-91b2-db159cf3806f.png) After PR #945: ![image](https://user-images.githubusercontent.com/26844016/209864524-70a8b095-056a-464b-9ff7-fd31397492ba.png) ![image](https://user-images.githubusercontent.com/26844016/209864558-9fd7a5d3-a965-4aa4-af62-a56846e331b3.png) Fix: ![image](https://user-images.githubusercontent.com/26844016/209865514-a9921096-b852-4402-8272-b76908851ad6.png) ![image](https://user-images.githubusercontent.com/26844016/209865550-d7842507-74fc-4f21-b407-9b8917df1fd8.png) # second bug > @simonebortolin @mattxwang I'm trying to write some regression tests for this feature. > > If I use GitHub's copy button to copy the following plain text, it preserves all the spaces: > > ``` > 1 leading space > 2 leading spaces and 2 trailing spaces > 3 internal spaces > 4 trailing spaces > ``` > > Using the new copy button with the same text in this PR branch of JTD gives this: > > ``` > 1 leading space > 2 leading spaces and 2 trailing spaces > 3 internal spaces > 4 trailing spaces > ``` > > It appears that the leading space from line 1 has been removed, and inserted on all the other lines. Moreover, the 4 trailing spaces have been removed. > > BTW, #924 didn't give a precise requirements spec, but mentioned the Microsoft docs UI; @mattxwang mentioned also the GitHub UI. It would be helpful to add a functional spec of what the JTD copy button is supposed to do, as a basis for regression tests. > > I'm not aiming at a rigorous test for the UI. Personally (using Safari at the default mag) I find the clipboard icon too small: it just looks like a box, and I can hardly see that there is a clip at the top. But I don't have a suggestion for a better icon. # third bug When I re-read the code after the second bug, I noticed a bug that it does not always select the text field to be copied correctly (in case there are also line numbers) is copied: ``` 1 2 3 4 # Ruby code with syntax highlighting and fixed line numbers using Liquid GitHubPages::Dependencies.gems.each do |gem, version| s.add_dependency(gem, "= #{version}") end ``` instead of ``` # Ruby code with syntax highlighting and fixed line numbers using Liquid GitHubPages::Dependencies.gems.each do |gem, version| s.add_dependency(gem, "= #{version}") end ``` Co-authored-by: Matt Wang <matt@matthewwang.me>
Hello everyone, this is my implementation for the copy button on the snippet (requested in #924)
The implementation is made 100% javascript as with or without a jekyll template modification you still have to execute some javascript code, and I consider it the best choice.
the button only appears if the mouse is over it, to allow the entire line to be read
the important CSS changes were made to make the copy button work even in the long code situation:
to avoid this: