sort simple list

Posted by @FlohGro, Last update 7 months ago

Orderes a simple list based on the state of the tasks.
All done items will be moved to the end into a section ##done

Steps

  • script

    // sort simple list
    
    // break draft into lines
    
    var lines = draft.content.split("\n");
    var begin = '';
    var end = '';
    var c = "- [x]";
    
    // sort lines based on their leading characters
    
    for(var line of lines){
    	var check = line.includes(c);
    	// if line contains c:
    	if (check) {
    		end += line + "\n";
    	} else if ( line.includes("## done")){
    		//ignore line!
    	} 
    	else{
    		begin += line + "\n";
    	}
    }
    
    // recompile / reorder draft
    begin = begin.slice(0,-1);
    end = end.slice(0,-1);
    editor.setText(begin + "\n" + "## done\n" + end + "\n");
    draft.update();
    editor.focus(draft); 

Options

  • After Success Default
    Notification Info
    Log Level Info
Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.