Extract code that positions caret at end of document