Possible to add a "copy" button for code blocks?

When a code block is long enough to need scrollbars, it’s painful – really painful – to copy all of it to the clipboard.

Dragging with the mouse is likely to lose the selection, or to select text outside the box as well.

Ctrl-A selects everything on the webpage, not only in the box.

The only way I’ve found that’s reliable is to select a small amount at the beginning or end, then use the scrollbars to go to the other end, and shift-click… which is unlikely to be most users’ first thought.

It would be very nice to have a little clipboard icon next to the code block – click it, and the entire code block (and only that block) goes onto the clipboard.



What about double clicking the start or end parenthesis or CTRL+SHIFT+R to select and then copy? I’m not against the button, but it seems easy enough with these shortcuts.

In my browser, ctrl-shift-R (like ctrl-R) reloads the page.

In my browser, double-clicking the parenthesis selects only the parenthesis, not the code block.

(I am talking about forum posts, not files in the IDE.)


Aha! Sorry, I misunderstood, thought you were talking about the IDE.

1 Like

+1 for this feature request, please
http://sccode.org has it too, perhaps the code could be gleaned?


It seems like the copy codeblock functionality may be built in to discourse now?

I found a few theme plugins that have all been discontinued and point to this thread: Copy codeblock contents to clipboard - announcements - Discourse Meta

From that thread:

This feature is off by default, but if your community could benefit from it, you can turn it on by enabling the show copy button on codeblocks site setting.

Would it be possible for a moderator to enable this setting? I also think it would be a great feature.


I just noticed a little copy thingy on the upper right corner of code blocks – thanks to whoever activated that!