Is there any way the text editor can capture TAB key events and actually indent code? Can one override the default behavior of the browser once the text editor gets the focus?

The reason I ask is obvious: If you write some code from scratch to explain something you can't go ahead and indent it as usual by a simple press of the TAB key but only by tedious banging of the space bar. Ok, one could edit stuff in another editor and post the formatted code right into the code section, but that's not how it's supposed to work, is it?