josdejong / jsoneditor

A web-based tool to view, edit, format, and validate JSON
http://jsoneditoronline.org
Apache License 2.0
11.62k stars 2.05k forks source link

Feature request: add "Copy to Clipboard" button on the Code Editor panel #127

Open uscore713 opened 10 years ago

uscore713 commented 10 years ago

I've scoured the docs and explored every corner of the UI, but I haven't been able to find a way to do a one-click operation to copy the contents of the Code Editor panel to the system clipboard.

Have I missed something? Or can this feature be easily implemented (and soon)?

josdejong commented 10 years ago

Thanks for your suggestion. Wouldn't you also like a "Paste from Clipboard" button in that case?...

I'm not sure whether this functionality should be a button inside the editor, or belongs to a button outside of it, in some application specific menu where you load/save documents.

Copy to clipboard is a tricky thing, there is no JavaScript based solution, solutions out there (like zeroclipboard and clippy) rely on flash, which will become less and less commonly installed on browsers.

uscore713 commented 10 years ago

Sure, a "Paste" button would be nice, but since, on most platforms, a generic paste operation is possible with a single keystroke (ok, a key "chord", but almost as easy).

Conversely, a "copy" involves several steps: (1) click inside the Code Editor panel, (2) select all of the text to be copied (in this case, control-A on Windows), then finally (3) press the key (or key chord) needed to copy the selected text in the window. This is why a single-button click would be dandy for this kind of thing.

I had no idea clipboard services haven't been standardized, but that now seems obvious given the security implications. There are some nice solutions described in this Stack Overflow question:

http://stackoverflow.com/questions/400212/how-to-copy-to-the-clipboard-in-javascript

Perhaps the "Clippy" solution would work, since it's apparently used by GitHub?

https://github.com/mojombo/clippy

In any event, thanks for taking the time to address this feature request.

uscore713 commented 10 years ago

By the way, kudos to you for providing such a great tool. ;)

uscore713 commented 10 years ago

By the way, kudos to you for providing such a great tool. ;)

uscore713 commented 10 years ago

You know, a cheap half-solution that would at least help would be a button that simply selects all the text in the Code Editor panel. That way a user would only have to click one button, then the key (chord) to copy the selection to the clipboard. Hey, at least it's a start.

josdejong commented 10 years ago

Thanks for your ideas. We could think about adding buttons for the following actions:

I think the first two are very handy and simple to implement, and make it easier to to copy/paste from clipboard "by hand". I'm a little cautious though stepping into this clipboard-swamp.

Copy/paste from clipboard can also be useful for the Tree Editor, but only when you offer them both.

We should be very careful with adding buttons to the editors menu. Before you know it you end up with so much buttons (completely replacing the regular context menu) that it ends up in chaos. It's important to keep things simple and to the point.