Can’t believe I’m asking for this basic-level help knowing there’s a lot of documentation concerning prefixes and RegEx expressions, but I can’t figure out how to create a script for:
Converting any line beginning with “- [ ]” to “- [x]”
A part of the script I currently use do this, using .replace() rather than a regex, assuming you already know how to target the lines you want to update (e.g. editor.getSelectedLineRange() followed by editor.getTextInRange())
You could do it with a regex that targets the start of the line, but since I don’t anticipate this particular series of characters being used in any other context, .replace() suits my purposes.
I also use an @inprogress tag for tasks I’m currently doing; the script fragment above removes the tag when marking the task done.
var r = editor.getSelectedLineRange()
var sel = editor.getTextInRange(r[0],r[1]).replace(/\n$/, '')
var sel = sel.split("\n")
var newsel = ""
sel.forEach(function(lineText){
if (lineText.includes("\t")) {
var tabCount = (lineText.match(/\t/g)||[]).length
}
if (lineText.includes("- [ ]")) {
lineText = lineText.replace("- [ ] ","- [x] ")
}
newsel += lineText + "\n"
})
editor.setTextInRange(r[0],r[1],newsel)
draft.update()
editor.setSelectedRange(r[0]+newsel.length-1,0)
Ahhhh. In that use case, yes. After I selected many rows, it worked as you expected. Thanks!
In my desired use case, selecting lines of text or specifically placing the cursor wouldn’t be necessary. Instead the script would scan the entire draft and action on those lines with the correct prefix.
I appreciate all the help and am happy to “buy coffee” for your time.