Can someone assist me in my JS? I’m trying to accomplish the following:
- Create new draft in editor view
- Apply JS syntax to #1
- Add ‘script’ tag to #1
I’m able to do all of these in JS, but not all in one action. The issue is when I use the editor
object followed by the draft
object, the draft
functions apply to the current draft open (prior to running the action) even though I use editor.activate()
and editor.isActive=1
, etc.
I thought it may be an issue where the action is writing the editor changes to disk before the draft is loaded in the editor view, but I get errors when using JS timeout methods and can’t figure this one out.
My code is below, appreciate the help!
// New Script Draft Action
// Prompt
var p = Prompt.create()
p.title = "Create New Script"
p.addTextField("draftTitle", "Draft Title", "")
p.addButton("Create")
var didSelect = p.show()
var textFieldContents = p.fieldValues["draftTitle"]
// Editor
editor.new()
editor.activate()
editor.isActive = 1
editor.setText("// " + textFieldContents)
editor.save()
// Draft
draft.languageGrammar = "JavaScript"
draft.addTag("script")
draft.update()