Fixed several issues with text selection (not yet fully browser-tested)