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.


  Returns

Type: Range | Null

a clone of the selection range, remember to detach after use!

getCommonAncestorContainer

Get the common ancestor of the selection in the focused document


  Returns

Type: Node

getEndContainer

Get the end container of the selection in the focused document


  Returns

Type: Node

getEndOffset

Get the end offset of the selection in the focused document


  Returns

Type: Number

getFocusedHierarchyNode

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


  Returns
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.


  Returns

Type: HierarchyNodeId | Null

getSelectedElement

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


  Returns

Type: Node | Null

The selected element, null if there is no selection or the selected element is a document.

getStartContainer

Get the start container of the selection in the focused document


  Returns

Type: Node

getStartOffset

Get the start offset of the selection in the focused document


  Returns

Type: Number

hasSelection

Test whether Fonto has a selection in any document

This is only false when there are zero document loaded


  Returns

Type: Boolean

isSelectionCollapsed

Get whether the selection in the focused document is collapsed


  Returns

Type: Boolean