Action

Move Line Down

Posted by agiletortoise, Last update 4 months ago

Move selected line(s) down one line. Bound to option-↓ keyboard shortcut by default.

Steps

  • script

    // grab ranges and text
    let [selStart, selLen] = editor.getSelectedRange()
    let [lnStart, lnLen] = editor.getSelectedLineRange()
    let lnText = editor.getTextInRange(lnStart, lnLen)
    let text = editor.getText()
    
    if (lnStart + lnLen >= text.length) { // check for end
    	// do nothing - can't move last line down
    }
    else {
    	// get next line range
    	let [nextLnStart, nextLnLen] = editor.getLineRange(lnStart + lnLen, 0)
    	let nextLnText = editor.getTextInRange(nextLnStart, nextLnLen)
    	if (!nextLnText.endsWith("\n")) {
    		nextLnText += "\n"
    		nextLnLen += 1
    	}
    	editor.setTextInRange(lnStart, lnLen + nextLnLen, `${nextLnText}${lnText}`)
    	editor.setSelectedRange(selStart + nextLnLen, selLen)
    }
    

Options

  • After Success Nothing
    Notification Error
    Log Level Error
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.