Visual Studio Dev Requests Code Copying with Proper Indentation, Mads K. Delivers
Microsoft's Visual Studio extension guru Mads Kristensen is at it again, taking a developer request and turning it into a handy tool, which he has put out there for experimentation and feedback.
This time he addressed an August 2020 post in Microsoft's Developer Community site for bug reports, feature requests and so on. Under the title "Easy copy code without indentation," the item from Thomas Ardal reads (unedited):
If often need to copy code from within Visual Studio and paste it into a blog post, some documentation, etc. When copying from indented code files (like a method in a class in a C# file) you get the spaces (or tabs) from the beginning of each line copied as well. Cleaning up these extra tabs after paste is boring work. To avoid doing that, I often mark the code I want copied and shift+tab the code until it is left aligned in the file and make a copy. Then ctrl+z to snap it back into place. It would be nice with a special shortcut, button, or something else that copies code so that it looks good pasted.
Yesterday (Oct. 25), Kristensen announced his solution, the Copy Nice extension in the Visual Studio Marketplace.
"You want to share some code you've written with a colleague, so you select it in the editor and hit Ctrl+C to copy it," he said in a blog post. "As you paste it in Outlook/Slack/Teams, you realize that the indentation levels are inconsistent due to your original selection. You must now either go back to Visual Studio and do a box selection and copy that, or manually fix the indentation issue in Outlook. You know this, yet you make this mistake almost every time. Sounds familiar?"
As an experiment, he worked up Copy Nice to remove unwanted indentation when code is copied from the editor, which required dealing with the thorny question of how the tool can be used for just unwanted indentations as opposed to wanted indentations. In addition to a code copy including indentation that needs to be manually stripped out later, another type of problem typically occurs when a developer neglects to include leading indentation when selecting text, instead pointing the cursor to the start of the text instead of capturing that indentation character to the left. That fails to capture indentation that may be wanted.
Kristensen indicated that annoying code copying indentation problems are commonplace, noting that multiple developers have requested a feature to address them, in addition to the August 2020 request from Ardal. Indeed, his post has garnered 68 votes and 13 comments.
The tool itself, released on Oct. 12 and updated yesterday, was nearing 440 installs at the time of this writing and earned an average 4.8 rating (0-5 scale) from six developers who reviewed it. One said: "Simple, yet effective. Works as advertised. This is especially useful when doing code reviews or pasting code into markdown format or in MS Teams. This fixes that super annoying removing formatted space. Lovely!"
Kristensen, who has authored some 185 extensions in the VS Marketplace, is now seeking more feedback on Copy Nice.
"If this feature is interesting to you, please install the Copy Nice extension and take it for a ride. Make sure to share any ideas and bugs on the GitHub issue tracker, and feel free to send pull requests too. The feature request ticket is a suitable place to share your comments and thoughts, so make sure to vote and comment there as well."
Kristensen's new Copy Nice tool essentially duplicates functionality in his Tweaks extension, he indicated.
David Ramel is an editor and writer for Converge360.