Document Selections

The most complete way to inspect and change the selection is through the Document object’s selection properties and commands. Most often you use the active document, eg:

$doc = Document.active

$selection = $doc.selection

Document Object Selection Properties

.selection v2.0.5

Returns a Selection object describing all selection(s) in the document, whether it be a single contiguous selection or a multi-part (discontinuous) selection, a text selection or a table selection. Read-only.

You can change the selection using the setSelection command.

.textSelection v1.1

Returns a TextSelection object for the first text selection in the document. Read-only.

.textSelections v1.1

Returns an array of TextSelection objects for all text selections in the document. Read-only. 

The ordering rules follow that of the Selection object’s textSelections property.

.tableSelection v1.1

Returns a TableSelection object for the first table selection in the document, or the @undefined value if there are no table selections. Read-only.

See the Selection object’s tableSelection property for more on table selections.

.tableSelections v1.1

Returns an array of TableSelection objects in the document, or the @undefined value if there are no table selections. Read-only.

The ordering rules follow that of the Selection object’s tableSelections property.

.selectionHistory v3.0

Returns an array of Selection objects, one for each prior selection the user has made in the document. The array is ordered from most recent (at index zero) to the oldest selection at the end. Read-only. 

The history array never contains the current selection. If the document has multiple split views, the selection history for the active split view is returned. 

The selection history is updated as edits are made in the document, so the selections are kept valid. However, some edits may disrupt the history in irreconcilable ways, eg: if a text replacement straddles an earlier selection. Large or complex multi-part selections may be coalesced or otherwise simplified by the selection history to improve performance.

Document Object Selection Commands

.setSelection selectionValue v1.1

This command changes the document’s selection so only the given object(s) is selected. The values allowed for selectionValue is quite liberal and can be any one of the following:

1. A Selection object (v2.0.5).

2. A TextSelection object.

3. A TableSelection object.

4. A Text object, indicating all its text should be selected (v2.0).

5. A Table object, indicating that the whole table should be selected (v2.0).

6. A FloatingContent object, indicating that the content should be selected (v2.0).

7. An Image object, indicating to select that image (v2.0.5).

8. A Note object, selecting the note reference in the document’s main body text (v2.0.5).

9. A Comment object, selecting the text to which the comment is applied (v2.0.5).

10. A TrackedChange object, selecting the text to which the change is applied (v2.0.5).

11. A Bookmark object, selecting the text to which the bookmark is applied (v2.0.5).

12. A ListItem object, selecting the list item or bullet. (v2.1.2).

13. An array that mixes any number of the objects listed above (v2.0).

The given object(s) must describe content in the document, or an error will be displayed. For example, if you provide an Image object, that image must be contained in the document text.


Previous Chapter
Document Commands
<<  index  >>
 
Next Chapter
Selection Objects