Questo componente del tema aggiunge un pulsante di copia ai blocchi di codice all’interno dei post di Discourse — perfetto per le comunità che condividono esempi di codice o articoli della knowledge base che richiedono la copia del testo.
Su desktop, il pulsante di copia appare al passaggio del mouse sul blocco.
Su mobile, il pulsante di copia è sempre visibile ma sposta il codice nel blocco verso il basso per evitare di oscurare la prima riga di codice se troppo lunga.
Tieni presente che questo funziona solo per i blocchi di codice generati da \ \\, e non per i blocchi di codice in linea.
Questo è un blocco di codice.
Copia questo testo.
Questo è un blocco di codice in linea. La copia non funziona qui.
Un grande ringraziamento a @j.jaffeux, che ha svolto la maggior parte dello sviluppo iniziale di questa funzionalità.
Curious if we are open to replacing the localized “copy”/“copied” text with icons? Maybe the copy icon for “copy”, and the checkmark icon for “copied”?
I’m open to adding a setting to the component. The reason I decided to go with localized text is it is clear what is happening, plus text can have a shorter height and still be readable. The aesthetic of it seemed to fit the use case better.
Also fixed a couple of bugs with older versions of Discourse that don’t have @ember/runloop and Promise from the rsvp library available. (Thanks to @jomaxro for the reports on those)
I like this a lot! But can the copy button be a visible-on-tap-only thing for mobile? I’m a little bummed by the consistent loss of screen space on mobile, an extra line for each code block:
since it’s opt-in you’d only enable it on sites where actually copying code blocks is a common activity as well
… that being said… the odds of any given code block being copied on mobile are vanishingly small, so I feel the ratio of UI to usage is off here, and would prefer an on-tap thing for mobile?
I would love to use this but as soon as I enabled it for my Grey Amber theme, my site became sluggish and unresponsive at times until I turn it off.
Has anyone experience this behavior, or could it tax the VPS that much when this is enabled?
The site is like 99.9% single code lines and I was hoping to switch into code blocks for this, so is not like is trying to fetch to convert any existing code. Or is it?
Do I have to give it some amount of time to normalize? It just kept bringing the site down temporarily and when sometimes a page would load it would say error and the try again message from discourse would show up.
Concerning, the possible perf bug, I tried a page with dozens of code blocks and got 0 issue, so I will need a reproduction before I can do anything @lcestou please
Try the new codeblock here:
rsync -a file.txt file_backup.txt
rsync -a /var/www/public_html/ /var/www/public_html_backup/