Bug 3709 - Remove trailing whitespace should be enabled by default
Summary: Remove trailing whitespace should be enabled by default
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: Text Editor ()
Version: unspecified
Hardware: PC Mac OS
: Low normal
Target Milestone: ---
Assignee: Mike Krüger
URL:
Depends on:
Blocks:
 
Reported: 2012-03-01 19:48 UTC by Aaron Bockover
Modified: 2012-03-05 07:05 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Aaron Bockover 2012-03-01 19:48:26 UTC
Really, why is this not the default setting?
Comment 1 Mikayla Hutchinson [MSFT] 2012-03-01 20:28:31 UTC
IIRC it was off by default for two reasons:
a) it was overzealous about removing whitespace from existing code, which caused a lot of noise on existing projects
b) the "virtual space" support - which allows the caret to be placed on empty lines as if there were whitespace to the level computed by the indenter - was buggy

TBH, I don't think stripping whitespace is the solution to the problem. It's hard to make it reliably strip whitespace only from new code and not existing code. Instead, we need to be smarter about not inserting it. 

We should look at what other editors do, but a good start might be:
a) make sure the virtual space support is usable, currently it's still impossible to correct it manually when the indenter position is wrong. Maybe backspace and left movement could be used to edit the virtual whitespace?
b) fix the C# smart indenter. If the previous line doesn't match what it computed, it should adjust its value for the current line by the same amount. 
c) when adding a new line, don't add indenter whitespace, instead just move the caret directly to the "virtual" position
d) don't add indenter whitespace in generated blank lines (e.g. event handlers, templates)
e) remove leading whitespace from a line when all the other text on that line is deleted, but keep the caret in the virtual position

Also, an option to highlight trailing whitespace and inconsistent newlines like git does would be nice.
Comment 2 Mike Krüger 2012-03-02 01:15:05 UTC
Souldn't be a default setting because of a). And trailing whitespace removal can lead to semantic changes (verbatim strings for example).

Virtual white spaces shouldn't be editable - the indent position can be correctly calculated - at least in the newresolver branch.

btw. many people want blank lines indented - it's for example a policy in nrefactory and I think it's more or less the "default".
Comment 3 Mikayla Hutchinson [MSFT] 2012-03-02 14:23:28 UTC
I think it's premature to call this "fixed" - even if we don't change the default, our handling of leading/trailing whitespace is subpar.

I stand by my point that removal is not the solution - if anything, your point that it can cause semantic changes reinforces this.

The policy setting should be "Do not indent blank lines", and MD should handle this by not inserting the indentation, as I described.
Comment 4 Mike Krüger 2012-03-02 17:13:26 UTC
The original thing is 'fixed' that there may be improvement of whitespace handling is different. Removal of whitespace is something some users want - like the one who opened this bug. 

I think that people know what they're doing can handle that. I don't have exact numbers here, but people WANT the indentation even on blank lines. It's not a bug or wrong feature. We need to allow that.

We could have a mode where indent doesn't insert blank lines and whitespaces are not truncated and indenting is just done virtually, I'll need to think about that.
The question is should we keep "truncate whitespaces then" ?
Comment 5 Mike Krüger 2012-03-05 07:05:32 UTC
Ok I implemented a 'virtual' indent mode - that's more or less what vs.net does.

I think monodevelop input works best in conjunction with the on the fly format - but the "input text" feature needs to be improved.

I need more use cases - but I think the virtual indent mode goes in the right direction.