Does anyone have an action for duplicating lines? Just like a text editor… hit a keyboard shortcut, and BOOM… line duplicated. ![]()
Pretty straightforward. Just a few lines of code:
// get range and text of current line
let [origSt, origLen] = editor.getSelectedRange();
let [st, len] = editor.getSelectedLineRange();
let lnText = editor.getTextInRange(st, len);
// insert new line
editor.setTextInRange(st+len, 0, lnText);
// restore selection
editor.activate();
editor.setSelectedRange(origSt, origLen);
Here’s it wrapped up in a duplicate line action.
1 Like
You are incredible!! ![]()
Is there any chance you would be able to update the script to duplicate lines regardless of where the line is? If the last line is duplicated, it does not create a new line.
This Result

Instead of This Result
