TextActionContext
The standard "context" variable that is passed to all JavaScript actions is a TextActionContext object, with the following properties and methods.
Properties
selectedRanges
Returns an array of Range objects.
Setting this property will immediately update the selected ranges in the document.
Read-only properties
- string: returns document's text as a string
- lineStorage: returns MRLineStorage object
- syntaxTree: returns SXZoneTree object
- itemizer: returns CEItemizer object
- textPreferences: returns CETextPreferences object
Methods
substringWithRange(range)
Returns the string in the document represented by the Range range.
For instance, if you wanted to grab the first ten characters in a document you would do it like so:
actions.performWithContext(context, outError) {
var range = new Range(0, 10);
var firstTen = context.substringWithRange(range);
};
applyTextRecipe(recipe, options)
Returns true
or false
; whether the CETextRecipe recipe was successfully applied to the document.
options is an optional argument that specifies formatting settings for your recipe. Available values are 0
(for no formatting) or a formatting constant.
insertTextSnippet(snippet, options)
Returns true
or false
; whether the CETextSnippet snippet was successfully inserted in the document.
options is an optional argument that specifies formatting settings for your snippet. Available values are 0
(for no formatting) or a formatting constant.