Possible to add "Select All" or "Copy" button to forum code boxes?

This is a feature that I’ve seen on other forums/platforms which makes it possible to basically click one button either to select all or copy right away the whole content of a code box. This makes it much faster to copy the code in full, as normally the box is limited in height, so you’ve got to scroll down in order to select everything from top to bottom. Trying to use Ctrl+A simply selects everything in the forum thread.

Just curious whether this kind of functionality is available in Discourse, either built in or maybe as a plugin?

Hi @tomasz86

Your cursor being at top of the box, did you try Ctrl+Shift+End ? I always try to get rid of boring mouse mandatory usage with any shortcuts I know from other softwares. Although your question is not very clear to me : typing this very answer, using Ctrl+A just works as intended, so maybe I misunderstand. Right now I’ll hit Ctrl+A and paste the capture =>

Should be possible now.

Here's a code box.

There was a (newish) setting to enable this. The thing is only visible when hovering on it.

1 Like

Thank you very much! :slightly_smiling_face:

Is this a setting or is it the only option (without adding custom CSS, etc.)? I work on touch screen devices a lot, but I couldn’t make the button appear there no matter what. It does, of course, show and work fine when using a mouse.

It’s great to have it regardless!

No configuration is available, it’s just an on/off setting. It is however always-visible on my mobile device so someone seems to have at least intended this to work. I guess if you’re on something touch but not mobile it might not be triggered. Perhaps you can set a mobile user agent or something, or it might trigger based on screen size, or you can custom-css it. On iOS with hover sensitive elements the first touch is typically hover and the second touch becomes an actual tap.

Actually I was testing on Android first and it didn’t show up… but I closed and re-opened the forum and now it is visible. Maybe the old CSS was still in the browser cache or something.

On Windows though, there is no button, however clicking (tapping) in the upper right corner still seems to work, with the “copied” text being displayed too.

I’ve heard about this one and it indeed sounds very cool but unfortunately other OSs haven’t followed :confused:. Samsung on their phones does provide an option to have an actual finger hover functionality but I’ve found it too annoying to be practical.

1 Like