-
-
Notifications
You must be signed in to change notification settings - Fork 171
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
feat: add copy button to viewer #70
feat: add copy button to viewer #70
Conversation
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.
Thank you for this PR, very very useful feature and simple implementation. Just to make the UI blend in with the rest of the application a bit better, I would make a few small changes, please see suggestions. With these changes I am happy to merge it right away
templates/pasta.html
Outdated
<button id="copy-button" class="copy-button"> | ||
<svg id="copy-icon" style="width:24px;height:24px" viewBox="0 0 24 24"> | ||
<path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" /> | ||
</svg> | ||
</button> |
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.
Let's keep this text based for now I think. It will also allow us to change the text
<a id="copy-button" class="copy-button">
Copy
</a>
const content = `{{ pasta.content_escaped() }}` | ||
|
||
btn.addEventListener("click", () => { | ||
navigator.clipboard.writeText(content) |
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.
Let's change the button text to Copied
here:
btn.innerText = "Copied"
templates/pasta.html
Outdated
padding: 8px; | ||
margin: 5px; |
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.
Adjusted placing for the new shape, plus change cursor type to show it's interactive:
padding: 3px;
margin: 3px;
cursor: pointer;
@@ -80,6 +80,10 @@ | |||
pub fn content_not_highlighted(&self) -> String { | |||
html_highlight(&self.content, "txt") | |||
} | |||
|
|||
pub fn content_escaped(&self) -> String { | |||
self.content.replace("`", "\\`").replace("$", "\\$") |
Check warning
Code scanning / clippy
single-character string constant used as pattern
@@ -80,6 +80,10 @@ | |||
pub fn content_not_highlighted(&self) -> String { | |||
html_highlight(&self.content, "txt") | |||
} | |||
|
|||
pub fn content_escaped(&self) -> String { | |||
self.content.replace("`", "\\`").replace("$", "\\$") |
Check warning
Code scanning / clippy
single-character string constant used as pattern
This suggestion would change it from a button to a link (to make it look the same as all the other actions): #70 (comment) |
Looks and works great, thank you so much! |
Closes #53