input: fix cursor's jump to end of input when user edit text at the middle of input

Solve #388 

/cc @dfilatov @narqo