Accessing the editor - lmparppei/BeatPlugins GitHub Wiki
Adding and replacing text
Once you manipulate the document, your changes will get parsed immediately. Note that if you make many changes, they can not be undone.
Beat.addString(String, index)
– add string at some indexBeat.replaceRange(index, length, string)
– replace a range with a string (which can be empty to remove text)
Selections
Beat.selectedRange()
– returns a range object with.location
and.length
propertiesBeat.setSelectedRange(location, length)
– set user selection (make sure you don't go out of range)Beat.scrollTo(index)
– scroll to character indexBeat.scrollToScene(scene)
– scroll to a scene objectBeat.scrollToLine(line)
– scroll to a line object
Formatting
Beat.reformat(line)
— reformat a single line in the screenplayBeat.reformatRange(location, length)
— reformat a range
Highlighting Text
You can temporarily change both text foreground and background color.
Beat.textBackgroundHighlight("#000000", location, length)
- set text background colorBeat.textHighlight("#000000", location, length)
- set foreground color
The highlights will disappear when the line is reformatted (for example when the user edits the affected line). You can remove any unused and useless highlights after you are done by forcing reformat: Beat.reformatRange(location, length)
.
Other
Beat.focusEditor()
— focus the editor window (from an HTML, for example)
Examples
Select the first scene heading
const scenes = Beat.scenes()
const scene = scenes[0]
Beat.setSelectedRange(scene.line.position, scene.line.string.length)
Replace a line in the screenplay
This example replaces every INT. as EXT.
for (const line of Beat.lines()) {
if (line.string.indexOf("INT.") == 0) {
Beat.replaceRange(line.position, 4, "EXT.")
}
}