Fixes UITextInput::getSelectionText()

Fixes issue #186

There were some semantical errors with its implementation. Rewrote most of the function using a more concise and intuitive algorithm.