Understand Svedit selection types
mainSvedit uses three distinct selection types to define what is currently active in the editor:
- Text Selection: Spans a range of characters within a string. Uses
anchor_offsetandfocus_offsetto define the range. - Node Selection: Spans a range of nodes within a
node_array. Thepathpoints to the array, and offsets indicate the node indices. - Property Selection: Targets a specific property of a single node (e.g., an
imageproperty).
Access the current selection via session.selection and set it programmatically using session.selection = new_selection.
// Text Selection Example
{
type: 'text',
path: ['page_1234', 'body', 0, 'content'],
anchor_offset: 1,
focus_offset: 1
}
// Node Selection Example
{
type: 'node',
path: ['page_1234', 'body'],
anchor_offset: 2,
focus_offset: 4
}
// Property Selection Example
{
type: 'property',
path: ['page_1', 'body', 11, 'image']
}