Script to convert Shift + Spacebar into four spaces on SE
You can use charAt to grab the preceding character and check it against a space, newline, or empty string (the case when the cursor is at the start). But let's not stop there.


white and pad are okay enough (white is probably unnecessary, but space would be a better name since newlines are typically included in the generic term "whitespace"), but those other names are truly horrible!
You should probably maintain their full text selection--beginning and end.


Updated code:

$("textarea").keydown(function (e) {
    if (e.shiftKey &amp;&amp; e.keyCode === 32) {
        var pad = "    ",
            text = this.value,
            start = this.selectionStart,
            end = this.selectionEnd,
            scroll = this.scrollTop,
            before = text.slice(0, start),
            after = text.slice(start),
            prevChar = before.charAt(before.length - 1);
        if (prevChar === "" || prevChar === " " || prevChar === "\n") {
            this.value = before + pad + after;
            this.selectionStart = start + pad.length;
            this.selectionEnd = end + pad.length;
            this.scrollTop = scroll;
            e.preventDefault();
        }
    }
});


Here are some future enhancement ideas:


Search for the preceding newline to ensure there is only whitespace before the cursor. This would fully stop expansion inside a sentence. Right now you can still insert four spaces in the middle right after a space.
Consider using ctrl + space so you can add ctrl + shift  + space for outdenting.
Shift/unshift every selected line instead of just the cursor position. Right now the { } button can be wrangled to do shifting, but it's cumbersome since you have to put some non-space character on the first line to get indentation.