GithubHelp home page GithubHelp logo

copynice's Introduction

Copy Nice for Visual Studio

Build

Download this extension from the Visual Studio Marketplace or get the CI build.


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. As you paste it in Outlook, 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?

Selection

It usually happens because you start your selection without the leading indentation. But every subsequent line has it. The result looks something like this when you paste it into Outlook:

Paste poorly formatted

With this extension, when code is copied it will automatically be formatted to take care of the leading indentation issue..

The result when pasting into Outlook looks like this:

Paste well-formatted

For Visual Studio to correctly identify when to strip indentation, these conditions must all be true:

  1. Selection mode is not Box Selection
  2. User selected multiple lines
  3. Selection must start on an empty indentation

This makes sure that what you copy is always what you expect. But in case you want to disable this feature, you can of course do that from the Edit -> Advanced -> Strip Leading Whitespace on Copy command.

Menu

How can I help?

If you enjoy using the extension, please give it a ★★★★★ rating on the Visual Studio Marketplace.

Should you encounter bugs or if you have feature requests, head on over to the GitHub repo to open an issue if one doesn't already exist.

Pull requests are also very welcome, since I can't always get around to fixing all bugs myself. This is a personal passion project, so my time is limited.

Another way to help out is to sponsor me on GitHub.

copynice's People

Contributors

madskristensen avatar

Stargazers

Grigory avatar Mahdi Ghanbari avatar Calvin A. Allen avatar  avatar Freeesia avatar Shodai Ikebe avatar  avatar  avatar Jorge Morales avatar  avatar  avatar  avatar Michael Hachen avatar Jan Karger ツ ☀ avatar Jan Ivar Z. Carlsen avatar Media Explorer avatar Bilgehan Zeki ÖZAYTAÇ avatar  avatar  avatar Christian Tang avatar Ahmed Walid avatar Shashi Kumar Nagulakonda avatar

Watchers

James Cloos avatar  avatar  avatar  avatar

copynice's Issues

Directives are not properly supported

Describe the bug
When present, directives in code either render output to be the one without "Copy nice" enabled or directives are cut in the middle

To Reproduce
Use the following code:

    bool IsCharEqual(ReadOnlySpan<char> t, int fromEnd, char upperExpectedChar)
    {
#if DEBUG
                System.Diagnostics.Debug.Assert(char.IsUpper(upperExpectedChar), $"'{upperExpectedChar}' is not in upper case");
                System.Diagnostics.Debug.Assert(fromEnd <= length, $"NOT fromEnd<=length for {fromEnd} <= {length}");
#endif
        return t[length - fromEnd] is { } c &&
               char.ToUpperInvariant(c) == upperExpectedChar;

    }

Expected behavior
Directives are shifted to the right when "Copy nice" copying action is invoked

Actual output

bool IsCharEqual(ReadOnlySpan<char> t, int fromEnd, char upperExpectedChar)
{
//original directive is cut 
DEBUG
            System.Diagnostics.Debug.Assert(char.IsUpper(upperExpectedChar), $"'{upperExpectedChar}' is not in upper case");
            System.Diagnostics.Debug.Assert(fromEnd <= length, $"NOT fromEnd<=length for {fromEnd} <= {length}");
//original directive is cut 
if
    return t[length - fromEnd] is { } c &&
           char.ToUpperInvariant(c) == upperExpectedChar;

}

Doesn't do anything

I tried with and without the option "strip leading whitespace on copy" and it does the same thing

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.