Action

sort checklist

Posted by FlohGro, Last update 6 months ago

UPDATES

6 months ago

name and description updated

created by @FlohGro / more on my Blog

sort checklist

This action sorts a list of checkboxes based on their state. All done items will be moved to the end of the draft into the section titled with „## done

[Configuration]

no configuration needed

[Usage]

Use this action when you have a checklist open and don’t want to delete done items with the clean done items in list action but instead move them into a „## done“ section. You can use the Show List action to open your lists quickly.


If you find this useful and want to support me you can

Buy Me A Coffee

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
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.