Fix the bug causing `java.lang.StringIndexOutOfBoundsException` crashes when showing the virtual keyboard
java.lang.StringIndexOutOfBoundsException