5

I noticed that marking, copying and pasting code snippets in StackOverflow is a bit cumbersome - even if it is only one line of code, as in the following example (there is a horizontal scrollbar - try to copy the entire line and you'll see what I mean):

enter image description here

How about adding a "Copy to clipboard" button, like it is done for example in Microsoft's MSDN and some other developer sites?

enter image description here

In this example, after clicking "allow access" once, the entire source code has been transferred to the clipboard and can now simply be pasted by using Ctrl+V into the source editor of your choice.

N.B. While this MSDN example seam to work in IE/Edge only, CodeProject does it like this, which I've tested with IE and with Chrome successfully:

enter image description here

Please consider, if some of you don't need to copy the entire code, it is still useful for many others.

16
  • From my personal experience it is seldomly required to copy entire snippets, mostly just bits and pieces or only certain lines to point out mistakes and errors etc.
    – Tim
    Oct 26, 2015 at 12:20
  • 2
    That link is IE/Edge only. See this screenshot for what a Firefox user sees on that same page.
    – theB
    Oct 26, 2015 at 12:31
  • 1
    @Tim Castelijns: Consider that SO code snippets are useful to be used in your code, and copying snippets to point out errors is fine, but it is not the only usage you can think of.
    – Matt
    Oct 26, 2015 at 14:23
  • It is strange for me to see so many downvotes. Other sites have this feature and it is useful, why not SO? Are you so conservative that you forget being innovative?
    – Matt
    Oct 26, 2015 at 14:24
  • @Matt maybe people find it not innovative enough. It only takes a couple seconds at most to copy a snippet "manually" (provided it's not a wall of code that requires scrolling)
    – Tim
    Oct 26, 2015 at 14:26
  • 1) Using Firefox CodeProject link just opens up a new window with the code in it. Nothing is actually copied to the clipboard. 2) How does the cost of implementing, testing, debugging cross-platform compatibility issues make this worth implementing? 3) How would you prioritize this feature request given the 2300 other open feature requests?
    – theB
    Oct 26, 2015 at 14:57
  • @theB: Well, it surely isn't a "must have", it is just and idea that came into my mind when I visited other sites. And I agree it is only useful if you have a couple of lines of code, a 4-liner wouldn't benefit from it.
    – Matt
    Oct 26, 2015 at 15:27
  • I think it's a well-intentioned idea, but the issue is really about "bloat" - I think SO favors a more spartan design/structure. this is motivated by issues of speed and performance. Are there add-ons you can use to accomplish this goal? maybe an extension? Again, there were many similar ideas in the past (once I proposed "Canned Comments" os we can easily put common cmments, but it was deemed unnecessary bec. we have extensions to use ) Oct 26, 2015 at 15:50
  • I think Tim has a point too, if you only need to copy-paste code once every 2 days.. . then those extra 4 seconds to copy the code manually is not quite a big deal Oct 26, 2015 at 15:51
  • 2
    @Coffee: If you know a nice extension I can use it would suit nicely - please let me know, which one does the job. Doesn't matter whether Chome, Firefox or IE as I need to have all 3 on my machine anyway.
    – Matt
    Oct 26, 2015 at 16:42
  • N.B. I can see that there are also a couple of upvoters, so not all users think this idea is bad. And since the answer from rene shows there is also source available, it might be worth thinking about integrating it into SO some day ... hope dies last ...
    – Matt
    Nov 5, 2015 at 10:02
  • 1
    Note, this feature was originally proposed about 5 years ago: meta.stackexchange.com/questions/32625/… Nov 5, 2015 at 16:10
  • Thanks for the link, and it received already 167 upvotes!
    – Matt
    Nov 5, 2015 at 16:18
  • Actually 190 upvotes, and 23 downvotes... So you've some catching-up to do on both fronts!
    – Shog9
    Nov 5, 2015 at 17:31
  • Wow, that is quite a lot :-D
    – Matt
    Nov 5, 2015 at 18:38

2 Answers 2

4

I didn't test it my self but I believe the Select Code Block Buttons Script over on StackApps might do the trick. The userscript is written by H.B..

Do notice that based on comments and answers not all script(s) seem to work for all browser/OS combinations so your mileage may vary.

12
  • May I ask a stupid question: How do I "inject" this script into Stackoverflow.com so it becomes available on each posted source?
    – Matt
    Oct 31, 2015 at 21:46
  • That is not a stupid question. You'll need to install TamperMonkey for Chrome or GreaseMonkey for FireFox. I'm not sure if there are similar plugins for IE, Opera or Safari. Those plugins enable you to paste the script in and then it will run at the pages it is designed for.
    – rene
    Oct 31, 2015 at 21:49
  • Thanks for your hint, that really brought me a step forward. I searched for TamperMonkey and GreaseMonkey at StackOverflow and found a useful question with answers I'd like to share: Manually adding a Userscript to Google Chrome
    – Matt
    Nov 2, 2015 at 14:37
  • Unfortunately this is being blocked by firm policies and cannot be installed.
    – Matt
    Jan 20, 2016 at 17:01
  • @Matt I'm afraid I can only fix that if I buy your firm...
    – rene
    Jan 20, 2016 at 18:47
  • Right, Rene! :-D Well, I just wanted to remark in some enironments this can be blocked.
    – Matt
    Jan 20, 2016 at 18:51
  • Why do not create a configurable option for people not to install the script but make the action button visible from a menu?
    – sergzach
    May 15, 2016 at 16:32
  • @sergzach maybe because that feature is not important enough to spend any dev-time on?
    – rene
    May 15, 2016 at 16:41
  • @rene May be. There must be huge amount of time to add a small button. Indeed I think that summary duration spending in discussions about it is more.
    – sergzach
    May 15, 2016 at 17:06
  • @sergzach not much dev-time...
    – rene
    May 15, 2016 at 17:13
  • @rene Many smart guys, but many different opinions...
    – sergzach
    May 15, 2016 at 17:22
  • @sergzach yes, that is what makes MSO such a fun place to be at ...
    – rene
    May 15, 2016 at 17:36
2

In my opinion this is a useful request. When actively answering questions, it may save a good amount of time. Especially when using the touch-pad only, because it is uncomfortable to select large texts.

This problem is solved by the Clipboardy Chrome extension, listed on StackApps. A button is inserted near each source and in one click the text is copied to clipboard. Additionally buttons for selecting, collapsing text and a popup with recently copied items (usage history) are available.
It works on github.com & nmjs.com too.

enter image description here

Install it from chrome store.
It's open source, so feel free to contribute or request new features.

2
  • Looks indeed quite useful, but unfortunately it dows not work for me: "Clipboardy (extension ID "....") is blocked by the administrator." This is due to firm policies.
    – Matt
    Jan 20, 2016 at 16:59
  • @Matt Thanks for trying the extension and feedback. The problem you experience is related with the group policies the administrator applied. But the extension is open source, so you can verify the code, make your own build and install it manually. Then ask admins to allow the installation. Jan 21, 2016 at 6:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .