-
-
Notifications
You must be signed in to change notification settings - Fork 604
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
Codeblock copy button #3501
base: develop
Are you sure you want to change the base?
Codeblock copy button #3501
Conversation
Codeblock copy button sxy
Thank you for opening your first PR! 🎉 We are very happy and would like to thank you very much for your contribution. If everything checks out, we'll make sure to review the PR as soon as possible and give feedback. In the meantime, to make the reviewing process as fast as possible, you can help us by checking the following things:
Furthermore, make sure that the linter does not complain, which will check your code on every new commit. If the linter task fails, make sure to run |
In typescript you can declare a sting array like: |
Thanks for the feedback, I've addressed those areas in the most recent commit |
Hi @nathanlesage, could you help us to review this pull request? |
Hi @kyaso, could you help us to review this pull request? |
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.
Overall, this looks promising! I have added some comments. Maybe @nathanlesage can also have a look when he has time again.
One thing I noticed: When you edit an existing codeblock, save the document, and then click the copy button, the newly added lines are not copied; only the previous version of the codeblock is copied. Not sure what might be causing this, but it's something we probably want to address before merging.
source/common/modules/markdown-editor/plugins/render-codeblock-button.ts
Outdated
Show resolved
Hide resolved
source/common/modules/markdown-editor/plugins/render-codeblock-button.ts
Outdated
Show resolved
Hide resolved
source/common/modules/markdown-editor/plugins/render-codeblock-button.ts
Outdated
Show resolved
Hide resolved
source/common/modules/markdown-editor/plugins/render-codeblock-button.ts
Show resolved
Hide resolved
@@ -210,6 +210,22 @@ body { | |||
border-bottom-left-radius: 4px; | |||
border-bottom-right-radius: 4px; | |||
} | |||
|
|||
.code-block-copy-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.
Is it possible to make the button and its placement look similar to this: #2375 (comment)
source/common/modules/markdown-editor/plugins/render-codeblock-button.ts
Outdated
Show resolved
Hide resolved
source/common/modules/markdown-editor/plugins/render-codeblock-button.ts
Outdated
Show resolved
Hide resolved
source/common/modules/markdown-editor/plugins/render-codeblock-button.ts
Outdated
Show resolved
Hide resolved
source/common/modules/markdown-editor/plugins/render-codeblock-button.ts
Show resolved
Hide resolved
Thank you for the reply. We will fix that. |
Heya, I'm back from a week-long conference, and just had a look. First of all, thank you for your efforts, it looks as if this will be a great addition to the app! Also, thanks to @kyaso for providing a very good and extensive code review. I think his review provides very good guidance in improving your PR. I added a few comments in there where I deemed it fit, but please orient yourself at Kyaso's comments first for a first round of review! :) |
Hi, I update my code based on the feedback from @kyaso. Also, I do not really understand the meaning of "Do not alter the language files." from @nathanlesage feedback. Does it mean I need to remove that line? |
@sxyxs This meant that you should not modify any of the language files. We have to do it via Zettlr Translate, i.e.: I need you to provide a list of new identifiers that you've introduced in your PR, and then I can add them to Zettlr Translate for everyone to translate. |
I understand that and start dealing with it. Thank you for the reply. |
Hi @nathanlesage, the only thing we have changed is to add a new copy button in each code block introduced in the PR's introduction. |
source/common/modules/markdown-editor/plugins/render-codeblock-button.ts
Show resolved
Hide resolved
source/common/modules/markdown-editor/plugins/render-codeblock-button.ts
Outdated
Show resolved
Hide resolved
@kyaso Thanks for your feedback and sorry for missing one point. I have fixed that. |
source/common/modules/markdown-editor/plugins/render-codeblock-button.ts
Show resolved
Hide resolved
Hi @kyaso, I have already fixed what you want me to fix. Please check. |
@sxyxs It looks fine to me. I think there is one minor improvement left which you could implement: #3501 (comment) @nathanlesage Would you mind having a final look over it again? Also, currently, the button text is a hardcoded "Copy", but I guess it should be translated? And last point: Do you think we should squash some commits before merging to clean up the commit history a bit? |
Hi @kyaso, fixed, please check. |
source/common/modules/markdown-editor/plugins/render-codeblock-button.ts
Show resolved
Hide resolved
@sxyxs Looks fine from my side. Would you mind rebasing your commits on top of the latest develop branch and also squash the temporary commits to clean up the commit history? And once that's done, @nathanlesage could have another look, when he has time? |
Ok, I will do it these days. |
Hi @kyaso, Is that what you want? |
@kyaso Hello? |
@sxyxs I think Kyaso is on vacation at the moment. I will have a look at the PR in the upcoming days. |
That will be great, thank you! |
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 found a few things, styling issues mainly. Please fix them while I pull the thing and test it out locally.
const lineCount = cm.lineCount() | ||
let incodeblock = false | ||
let codesblocks = new Array<string>() | ||
let codeblock = '' |
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.
Why don't you store the codeblock as an array? That would (a) make line 39 less awkward since you just had to push the line, would (b) save you from slicing in line 44, and (c) in line 71 you could simply write codeblock.join('\n')
into the clipboard.
const codeBlockRE = /^(?:\s{0,3}`{3}|~{3}).*/ | ||
const lineCount = cm.lineCount() | ||
let incodeblock = false | ||
let codesblocks = new Array<string>() |
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 codesblocks = new Array<string>() | |
const codeblocks: string[] = [] |
source/common/modules/markdown-editor/plugins/render-codeblock-button.ts
Show resolved
Hide resolved
if (document.getElementsByClassName(codeblockClassClose).length === codeblocks.length) { | ||
for (let i = 0; i < codeblocks.length; i++) { | ||
const codeBlock = codeblocks[i] | ||
if (codeBlock === undefined) { |
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 should never be true! Did you add this because you were encountering undefined-issues? If so then there is a serious bug further above in this file. If not, then it should be safe to delete this.
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.
@nathanlesage Yes, there will have some issues if I delete this one. I will take look into it to find a better solution.
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.
Hi @nathanlesage, should I delete line 53 or 56 or both?
codeBlock.childNodes[1].addEventListener('click', () => clipboard.writeText(codeBlockText)) | ||
} else { | ||
// Add property for copy button | ||
let copyButton = document.createElement('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 copyButton = document.createElement('button') | |
const copyButton = document.createElement('button') |
let copyButton = document.createElement('button') | ||
copyButton.className = 'code-block-copy-button' | ||
copyButton.innerHTML = '<clr-icon shape="copy"></clr-icon>' | ||
copyButton.setAttribute('title', 'Copy this code block to clipboard') |
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.
Please make this translatable and provide the translation keys for me to add to Zettlr translate once it's finished.
@@ -62,6 +62,11 @@ export default function (): any { | |||
type: 'checkbox', | |||
label: trans('dialog.preferences.display.render_emphasis'), | |||
model: 'display.renderEmphasis' | |||
}, | |||
{ | |||
type: 'checkbox', |
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 think it is safe to not make this toggleable. The codeblock button does not change the rendering of any part of the editor, hence we should remove this option. Possibly this also involves removing the option from other files your PR touches.
@@ -182,7 +182,8 @@ export default defineComponent({ | |||
math: (global as any).config.get('display.renderMath'), | |||
tasks: (global as any).config.get('display.renderTasks'), | |||
headingTags: (global as any).config.get('display.renderHTags'), | |||
tables: (global as any).config.get('editor.enableTableHelper') | |||
tables: (global as any).config.get('editor.enableTableHelper'), | |||
codeBlockButton: (global as any).config.get('display.renderCodeBlockButton') |
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.
The quicklook editor has been nuked in the meantime, so you can remove this change.
Description
Added a plugin to add a button to copy the contents of a codeblock as #2375.
Changes
source/common/modules/markdown-editor/plugins/render-codeblock-button.ts
dialog.preferences.display.render_codeblock_button
Additional Information
yarn lint
:source/common/modules/markdown-editor/plugins/render-codeblock-button.ts
error The array literal notation [] is preferable
[]
on line 29 , I cannot do theclipboard.writeText
operation on line 64.Tested on:
Ubuntu 20.04 LTS