Use insertAtCaret instead of setInputValue when possible

This is a improvement of the previous commit.