Implement most of the features of TextField

This function is a bit large, can you split it up a bit?