Action

Sort

Posted by agiletortoise, Last update 6 months ago

Sort lines in alpha order.

Steps

  • script

    // sort methods
    
    function alphaSort(vals, caseSensitive, ascending) {
    	let result = vals.sort(function(a, b) {
    		if (!caseSensitive) {
    			a = a.toLowerCase();
    			b = b.toLowerCase();
    		}
    		return a.localeCompare(b);
    	});
    	if (!ascending) {
    		result = result.reverse();
    	}
    	return result;
    }
    
    
    // Alpha sort selected lines.
    
    var lnRange = editor.getSelectedLineRange();
    var ln = editor.getTextInRange(lnRange[0],lnRange[1]);
    
    var lines = alphaSort(ln.split('\n'), true, true);
    editor.setTextInRange(lnRange[0],lnRange[1],lines.join('\n'));
    

Options

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