GitDiffMargin icon indicating copy to clipboard operation
GitDiffMargin copied to clipboard

Opening file changes its encoding

Open tpluscode opened this issue 8 years ago • 10 comments

Any file that I open with Visual Studio 2017 changes encoding from UTF-8 to us-ascii. I can confirm this in versions 15.3.3+. Looks like this

Before opening:

> file -b source.cs
text/plain; charset=utf-8

After opening:

> file -b source.cs
text/plain; charset=us-ascii

Immediately after opening the margin indicates that entire file has changed even though git correctly recognizes changed lines. Git does however show the BOM character as being added. Confusing and annoying.

I though this was solely related to #127 but it's more complex. True enough, when I installed 3.5.0 the file's encoding doesn't change but still the entire margin is in blue...

tpluscode avatar Sep 26 '17 20:09 tpluscode

@tpluscode Do you know about Fix File Encoding

When you edit a UTF-8 file in Visual Studio, it adds the byte order mark (BOM) sequence to the beginning of the file. You can select an encoding manually, but you need to do it each time you reopen the file.

I though this was solely related to #127 but it's more complex

I can't imagine this can be related because this is used only when you do a diff in the diff window!

True enough, when I installed 3.5.0 the file's encoding doesn't change but still the entire margin is in blue...

Might be due to Visual Studio which add the BOM

Could you please try to uninstall GitDiffMargin and do the test with the file to see if the encoding is changed, because I can't imagine that GitDiffMargin change the encoding!

Thanks for reporting this!

laurentkempe avatar Sep 27 '17 07:09 laurentkempe

Okay now I'm confused. I thought I'd nailed it yesterday but now whichever version I try it seems to work fine 😥.

However, it still highlights the entire margin as modified even though neither VS nor git detects any changes.

tpluscode avatar Sep 27 '17 08:09 tpluscode

It is really GitDiffMargin displayed and not Visual Studio Track Changes ?

laurentkempe avatar Sep 27 '17 10:09 laurentkempe

Yes, definitely Git Diff Margin. Click it and entire file appears in the pop-up

tpluscode avatar Sep 27 '17 10:09 tpluscode

@tpluscode Open the folder containing the file that was giving you problems. Then work your way from there to the root of the drive, looking in each folder for a file called .editorconfig. When you find it, look in that file for any lines starting with charset. Let me know if you find any (and if it applies to the source file, what its value is).

Visual Studio 15.3 added support for this property. It shouldn't apply by simply opening a file, but it definitely will apply when you click save.

sharwell avatar Sep 27 '17 11:09 sharwell

Thanks @sharwell for this suggestion. I don't use .editorconfig and there is no anywhere up the tree. Not sure where it would've come from.

But, maybe I can actually create one to enforce expected behaviour?

tpluscode avatar Sep 27 '17 12:09 tpluscode

@tpluscode Do you use ReSharper?

laurentkempe avatar Sep 27 '17 13:09 laurentkempe

I do. Anything in particular I should look for?

tpluscode avatar Sep 27 '17 13:09 tpluscode

@tpluscode Maybe you should look at File Formatting Info window which would display if any editorconfig or others are modifying your file.

laurentkempe avatar Sep 28 '17 04:09 laurentkempe

image

tpluscode avatar Sep 28 '17 16:09 tpluscode