Do not waste your time on a boilerplate code, you can duplicate the line at the caret simply by pressing &shortcut:EditorDuplicate;.