Quite often, a question is asked with excessive whitespace in front of all the code, like this:
var a = 1;
var b = 3;
if(a > 0) {
b--;
alert(b);
}
Within 10 minutes, I was able to screenshot not one, not two, but three examples of this sort of thing happening. These were all corrected through editing, but it begs the question: Why does this happen so often?
What is even more curious is that the code formatting button and the Ctrl+K shortcut physically do not let you format code with excess whitespace like this: The selected code toggles between an indent of zero to four spaces.
So my questions are:
- How do users manage to indent code with a ridiculous amount of spaces when pasting or writing code into their question?
- And more importantly, how can we reduce occurrences like these?
Is some sort of a 'excessive whitespace' warning tooltip needed?
CTRL-K
an appropriate number of times to unindent.Ctrl-K
won't clean all the extra space if your starting indentation is not a multiple of 4.Ctrl+K
shortcut. I always wondered why they never implemented indentation with the standardTab
/Shift+Tab
keys.