Action

Previous Placeholder <|>

Posted by agiletortoise, Last update over 1 year ago

Find and select the previous placeholder text in the draft. Mean for use with templates as described in this forum tip

Placeholders are any text matching <|fieldname>, where “fieldname” is optional.

Steps

  • script

    // define the placeholder to find
    const placeholderRe = /<\|.*?>/gm
    
    // grab values to use
    let [st, len] = editor.getSelectedRange()
    const text = editor.getText()
    
    // function to locate the next matching placeholder
    function findPrevious(str, st) {
    	let matches = []
    	while(match = placeholderRe.exec(text)) {
    		matches.push(match)
    	}
    	for (let match of matches.reverse()) {
    		let pos = match["index"]
    		if (pos < st) {
    			return [pos, match[0].length]
    		}
    	}
    	return [null, null]
    }
    
    // find next placeholder and select it
    let [placeSt, placeLn] = findPrevious(text, st)
    if (placeSt) {
    	editor.setSelectedRange(placeSt, placeLn)
    	editor.activate()
    }
    

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.