madskristensen / Tweakster

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

Copy without indentation copies incorrect text to clipboard #96

Open Diesel1017 opened 2 years ago

Diesel1017 commented 2 years ago

Extension version: v1.1.125 VS Version: 17.0.4

When in C# file selecting indented sql string and copy to clipboard, a part of the selected text is not copied to clipboard!

VS_Tweaks_2022_Error_01 VS_Tweaks_2022_Error_02

icnocop commented 2 years ago

I discovered this issue occurs depending on the text selection on the first line.

For example, in the screenshot:

VS_Tweaks_2022_Error_02

Notice the selection is not at column 0, and more like column 14, so Tweaks will incorrectly strip the first 14 characters of every line in the selection.

In this scenario, I'm thinking maybe the 3 lines that were copied/pasted incorrectly had a smaller number of characters at the beginning, such as tabs being used instead of spaces, and so when the first 14 characters were trimmed on these lines, some of the text was also actually removed unexpectedly.

phizch commented 1 year ago

In this scenario, I'm thinking maybe the 3 lines that were copied/pasted incorrectly had a smaller number of characters at the beginning, such as tabs being used instead of spaces, and so when the first 14 characters were trimmed on these lines, some of the text was also actually removed unexpectedly.

That is probably correct. The extension currently only counts the number of whitespace characters before the selection on the first line, and then removes that number of characters from the subsequent lines.

This works when all the lines have only spaces, or only tabs, but when the first line has spaces, and subsequent lines have tabs, with e.g. a width of 4, then it removes too much from the front of the line.

    selection starts here
    ↓ 
····4 spaces
→   1 tab

Paste
↓
4 spaces
ab

You can turn on visible whitespace in Edit > Advanced > View White Space, or in the Options, under Text Editor > General > Display > View whitespace.