SelectionManager
How to get SelectionManager
ES2015+:
import SelectionManager from 'fontoxml-selection/selectionManager'
ES5:
define([
'fontoxml-selection/selectionManager'
], function (
SelectionManager
) {
});
Type: Class
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
Name | Type | Description |
---|---|---|
focusedDocumentId | DocumentId | Null | The DocumentId that is currently focused |
newFocusedDocumentNotifier | Notifier | Notifier which can be used to be notified when another document is focused. |
selectionChangeNotifier | Notifier | Notifier which can be used to be notified when the selection changes. |
Methods
Name | Description |
---|---|
cloneSelectionRange | Get a clone of the selection range. Remember to detach this range after use. Consider using other methods on the SelectionManager instead. |
getCommonAncestorContainer | Get the common ancestor of the selection in the focused document |
getEndContainer | Get the end container of the selection in the focused document |
getEndOffset | Get the end offset of the selection in the focused document |
getFocusedHierarchyNode | Returns the currently focused hierarchy node, or null if there is no selection. |
getFocusedHierarchyNodeId | 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. |
getSelectedElement | Get the currently selected element, being the element fully contained in the selection, or the common ancestor of the selection. |
getStartContainer | Get the start container of the selection in the focused document |
getStartOffset | Get the start offset of the selection in the focused document |
hasSelection | Test whether Fonto has a selection in any document This is only false when there are zero document loaded |
isSelectionCollapsed | Get whether the selection in the focused document is collapsed |