Action

Smart Tab

Posted by jochi, Last update 4 months ago

Inserts 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 indent 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 indent_lines = (l) => {
    
    	let lines;
    
    	if (l.match(list_re)) {
    		lines = l.replace(list_re, "\t$1");
    	} else {
    		lines = l.replace(/^/gm,"\t");
    	}
    	return lines;
    
    }
    
    let tabbed_text = indent_lines(lnText);
    editor.setTextInRange(lnStart, lnLen, tabbed_text);
    editor.setSelectedRange(selStart + 1);

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.