SelectionManager

Type: Class

How to get selectionManager?

JavaScript

import selectionManager from 'fontoxml-selection/src/selectionManager.js'

Manages the selection by exposing the selected range in various ways. The selection manager also tracks the ID of the document containing the selection (the "focused document"), as well as the hierarchy node ID corresponding to the view containing this selection. This last ID helps to disambiguate cases where the selection could be mapped to multiple views.

The focused document is updated automatically whenever an operation changes the selection. If this operation's StepData also contains a hierarchyNodeId property, that hierarchy node becomes the new focused hierarchy node. This focused hierarchy node ID may be adjusted automatically if the selection is not mappable to the corresponding view and ends up in a different view instead.

Properties

focusedDocumentId

Type: DocumentId | NULL

The DocumentId that is currently focused

newFocusedDocumentNotifier

Type: Notifier

Notifier which can be used to be notified when another document is focused.

selectionChangeNotifier

Type: Notifier

Notifier which can be used to be notified when the selection changes.

Methods

cloneSelectionRange

Type: Function

Get a clone of the selection range. Remember to detach this range after use.

Consider using other methods on the SelectionManager instead.

Returns

getCommonAncestorContainer

Type: Function

Get the common ancestor of the selection in the focused document

Returns

getEndContainer

Type: Function

Get the end container of the selection in the focused document

Returns

getEndOffset

Type: Function

Get the end offset of the selection in the focused document

Returns

getFocusedHierarchyNode

Type: Function

Returns the currently focused hierarchy node, or null if there is no selection.

Returns

getFocusedHierarchyNodeId

Type: Function

Returns the ID of the current focused hierarchy node, or null if there is none.

If there is no selection, this may still return the ID of a focused placeholder.

Returns

getSelectedElement

Type: Function

Get the currently selected element, being the element fully contained in the selection, or the common ancestor of the selection.

Returns

getStartContainer

Type: Function

Get the start container of the selection in the focused document

Returns

getStartOffset

Type: Function

Get the start offset of the selection in the focused document

Returns

hasSelection

Type: Function

Test whether Fonto has a selection in any document

This is only false when there are zero document loaded

Returns

isSelectionCollapsed

Type: Function

Get whether the selection in the focused document is collapsed

Returns