madskristensen / Tweakster

A Visual Studio extension
Apache License 2.0
238 stars 23 forks source link

Copy without indentation doesn't work for fully selected lines #105

Open theperiscope opened 1 year ago

theperiscope commented 1 year ago

This issue is somewhat related to #96.

Environment: VS2022 17.3.0, latest version of extension, .NET 5 C# code

Test C# code:

        public int EntityTypeId
        {
            get { return 1006; }
        }

Steps to reproduce:

  1. Select from immediately before public to }
  2. CTRL-C
  3. CTRL-V into Notepad (text copied without indentation)
  4. Select all 4 lines completely, from first column
  5. CTRL-C
  6. CTRL-V into Notepad (text copied with indentation)
  7. Select from one space before public to }
  8. CTRL-C
  9. CTRL-V into Notepad (text copied with 1 space indentation)

Actual Results: Based on above steps, I can infer that to consistently tie the 3 cases above the C# code is copied without indentation stripping amount of space equal to start position where the selection begins - so for first characters result is 0.

Expectation: Strip indentation independent of where the start of the selection is.

phizch commented 1 year ago

The way it currently works is that it strips the first n characters from subsequent lines, where n is the number of whitespace characters between the start of the first line and the start of the selection.

E.g. if you have 8 spaces line in your example, and start the selection 4 spaces before the start of public, only 4 spaces will be removed from the start of the rest of the lines in the selection.

No checks are done to see if there are more whitespaces in the selection before the first non-whitespace character, and worse, no checks are made to make sure no non-whitespace characters are removed on subsequent lines.