Action

Insert Workspace Link

Posted by agiletortoise, Last update over 4 years ago

Prompt to select a workspace, and Insert a [[w:Workspace]] style link to the workspace at the cursor.

Steps

  • script

    
    let f = () => {
    	// prompt for title and tags
    	let p = Prompt.create();
    	p.title = "Insert Workspace Link"
    	p.message = "Insert a link to open a workspace in the current draft."
    	
    	let workspaces = Workspace.getAll();
    	let names = workspaces.map(w => w.name);
    	p.addSelect("name", "Workspace", names, [], false);
    	p.addButton("Insert Link");
    	
    	if (!p.show()) { return false; }
    		
    	// insert link in current draft
    	let selected = p.fieldValues["name"];
    	if (selected.length == 0) { return false; }
    	let name = selected[0];
    	
    	let linkText = `[[w:${name}]]`;
    	let [st, len] = editor.getSelectedRange();
    	editor.setSelectedText(linkText);
    	editor.setSelectedRange(st+linkText.length, 0);
    	
    	return true;
    }
    
    if (!f()) {
    	context.cancel();
    }

Options

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