Likewise, looks like you keep repeating the code to focus the editor and put the caret at the end of the text, so that should be moved to a function too.