Fixes crash when inserting text at caret position while autocompletion (http://crashes.to/s/2ab1ead09d9)