Is it possible to fold large blocks of code in IntellJ, select a section of code that encloses the folded section, and only copy the text that is visible?
For instance, if I have a JSON file like:
{
"list1" : [
1,
2,
3
],
"list2" : [
"a",
"b",
"c"
]
}
and I fold the lists so the IDE displays them as:
{
"list1" : [...],
"list2" : [...]
}
Is there a way to copy ONLY the text displayed above? Regular copy includes the code that is hidden from view.
Interestingly, when copying within IDEA, it keeps the folded state (See for instance the screenshot attached to IDEA-139523). This implies that the data is in the clipboard somehow, though perhaps it's only in an IDEA-specific format that other programs can't read.
The general feature request to do what you're asking appears to be in the JetBrains ticket tracking system as IDEA-126233. There's no indication in there of a workaround or when it may get worked on.
Unfortunately, your options seem to be limited here.
- You can use an external tool as suggested in another answer to do the formatting you need. Especially if it's limited to JSON formatting, you may be able to find some other standalone tool you can run in your development environment that meets your security and performance requirements.
- I recommend voting for that ticket in the JetBrains ticketing system. Might not accomplish a whole lot, but at least let them know that another person would find it useful. If you have further explanation or description that might be related that you think isn't described well enough in the existing ticket, you could add your comments to help flesh it out.
- Since the data appears to be there somewhere in the IDEA clipboard since it retains the folding when copying within the application, presumably it'd be possible to add this "Copy as displayed" feature within some sort of plugin. If you really need this and can't find an existing plugin that does it, you may want to see how hard it would be to write this plugin yourself.
- If you have a JetBrains support contract, you may want to contact them and see if they can help you further. While I doubt they can do a whole lot more than note your interest in the development of the ticket already in their system, it can't hurt to ask, and perhaps they're aware of some other workaround that would be useful to you.
Sorry for the rather unsatisfying answer, but I suspect it's the best one can have at the moment.