Action

Move Line Up

Posted by agiletortoise, Last update over 2 years ago

Move selected line(s) up 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 (!lnText.endsWith("\n")) { // make sure it ends in a line feed
    	lnText += "\n"
    	lnLen += 1
    }
    	
    if (lnStart == 0) { // check for beginning
    	// do nothing - can't move first line up
    }
    else {
    	// get previous line range
    	let [prevLnStart, prevLnLen] = editor.getLineRange(lnStart - 1, 0)
    	let prevLnText = editor.getTextInRange(prevLnStart, prevLnLen)
    	editor.setTextInRange(prevLnStart, lnLen + prevLnLen, `${lnText}${prevLnText}`)
    	editor.setSelectedRange(selStart - prevLnLen, 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.