Action

Smart Detab

Posted by jochi, Last update 24 days ago

Removes a tab the beginning of each of the selected lines.

If it is a list (starts with a tab followed by a “-“, “*”, or “+” followed by a space), it will outdent and move the cursor to the end of the line.

Steps

  • script

    // list patterns
    const list_re = /^\t/gm;
    
    // grab state
    let [lnStart, lnLen] = editor.getSelectedLineRange();
    let lnText = editor.getTextInRange(lnStart, lnLen);
    let [selStart, selLen] = editor.getSelectedRange();
    
    let outdent_lines = (l) => {
    
    	let lines;
    
    	if (l.match(list_re)) {
    		lines = l.replace(list_re, "");
    	}
    	return lines;
    
    }
    
    let detabbed_text = outdent_lines(lnText);
    editor.setTextInRange(lnStart, lnLen, detabbed_text);
    editor.setSelectedRange(selStart + selLen -1, 0);

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.