Expand all

ve.ce.Document

Extends

Constructor

new ve.ce.Document(model, surface) #

ContentEditable document.

Parameters:

Name Type Description
model ve.dm.Document

Model to observe

surface ve.ce.Surface

Surface document is part of

Source:
ContentEditable document.

Methods

getBranchNodeFromOffset(offset) → {ve.Node|null} #

Get a node at an offset.

Parameters:

Name Type Description
offset number

Offset to get node at

Inherited from:
Source:

Returns:

Node at offset

Type
ve.Node | null
Get a node at an offset.

getCoveredSiblingGroups(range) → {Array} #

Get groups of sibling nodes covered by the given range.

Parameters:

Name Type Description
range ve.Range
Inherited from:
Source:

Returns:

Array of objects. Each object has the following keys:

  • nodes: Array of sibling nodes covered by a part of range
  • parent: Parent of all of these nodes
  • grandparent: parent's parent
Type
Array
Get groups of sibling nodes covered by the given range.

getDir() → {string} #

Get the document view directionality

Source:

Returns:

Directionality (ltr/rtl)

Type
string
Get the document view directionality

getDirectionalityFromRange(range) → {string} #

Get the block directionality of some range

Uses the computed CSS direction value of the current node

Parameters:

Name Type Description
range ve.Range
Source:

Returns:

'rtl', 'ltr'

Type
string

Get the block directionality of some range

Uses the computed CSS direction value of the current node

getDocumentNode() → {ve.BranchNode} #

Get the root of the document's node tree.

Inherited from:
Source:

Returns:

Root of node tree

Type
ve.BranchNode
Get the root of the document's node tree.

getLang() → {string} #

Get the document view language

Source:

Returns:

Language code

Type
string
Get the document view language

getNodeAndOffset(offset) → {ve.ce.NodeAndOffset}private #

Calculate the DOM position corresponding to a DM offset

If there are multiple DOM locations, heuristically pick the best one for cursor placement

Parameters:

Name Type Description
offset number

Linear model offset

Source:

Returns:

Position

Type
ve.ce.NodeAndOffset

Throws:

Offset could not be translated to a DOM element and offset

Type
Error

Calculate the DOM position corresponding to a DM offset

If there are multiple DOM locations, heuristically pick the best one for cursor placement

getSlugAtOffset(offset) → {HTMLElement} #

Get a slug at an offset.

Parameters:

Name Type Description
offset number

Offset to get slug at

Source:

Returns:

Slug at offset

Type
HTMLElement
Get a slug at an offset.

nodeAttached(node) #

Callback when a node is attached with ve.Node#setDocument

The node and all its children are guaranteed to be attached

Parameters:

Name Type Description
node ve.Node

The node attached

Inherited from:
Source:

Fires:

Callback when a node is attached with ve.Node#setDocument

The node and all its children are guaranteed to be attached

nodeDetached(node) #

Callback when a node is attached with ve.Node#setDocument

The node and all its children are guaranteed to be attached

Parameters:

Name Type Description
node ve.Node

The node detached

Inherited from:
Source:

Fires:

Callback when a node is attached with ve.Node#setDocument

The node and all its children are guaranteed to be attached

rangeInsideOneLeafNode(range) → {boolean} #

Test whether a range lies within a single leaf node.

Parameters:

Name Type Description
range ve.Range

The range to test

Inherited from:
Source:

Returns:

Whether the range lies within a single node

Type
boolean
Test whether a range lies within a single leaf node.

selectNodes(range, [mode]) → {Array} #

Gets a list of nodes and the ranges within them that a selection of the document covers.

Parameters:

Name Type Attributes Default Description
range ve.Range

Range within document to select nodes

mode string optional
'leaves'

Type of selection to perform:

  • leaves: Return all leaf nodes in the given range (descends all the way down)
  • branches': Return all branch nodes in the given range
  • covered: Do not descend into nodes that are entirely covered by the range. The result is similar to that of 'leaves' except that if a node is entirely covered, its children aren't returned separately.
  • siblings: Return a set of adjacent siblings covered by the range (descends as long as the range is in a single node)
Inherited from:
Source:

Returns:

List of objects describing nodes in the selection and the ranges therein:

  • node: Reference to a ve.Node
  • range: ve.Range, missing if the entire node is covered
  • index: Index of the node in its parent, missing if node has no parent
  • indexInNode: If range is a zero-length range between two children of node, this is set to the index of the child following range (or to node.children.length + 1 if range is between the last child and the end). If range is a zero-length range inside an empty non-content branch node, this is 0. Missing in all other cases.
  • nodeRange: Range covering the inside of the entire node, not including wrapper
  • nodeOuterRange: Range covering the entire node, including wrapper
  • parentOuterRange: Outer range of node's parent. Missing if there is no parent or if indexInNode is set.
Type
Array

Throws:

  • Invalid mode

    Type
    Error
  • Invalid start offset

    Type
    Error
  • Invalid end offset

    Type
    Error
  • Failed to select any nodes

    Type
    Error
Gets a list of nodes and the ranges within them that a selection of the document covers.

setDir(dir) #

Set the document view directionality

Parameters:

Name Type Description
dir string

Directionality (ltr/rtl)

Source:
Set the document view directionality

setLang(lang) #

Set the document view language

Parameters:

Name Type Description
lang string

Language code

Source:
Set the document view language

Events

langChange() #

Language or direction changed

Source:
Language or direction changed

nodeAttached(node) #

A node has been attached with ve.Node#setDocument . Its descendants are guaranteed to be attached too (and the event is emitted for descendants first, and for siblings in their order in the children list)

Parameters:

Name Type Description
node ve.Node

The node that has been attached

Inherited from:
Source:
A node has been attached with ve.Node#setDocument .

nodeDetached(node) #

A node has been detached with ve.Node#setDocument . Its descendants are guaranteed to be detached too (and the event is emitted for descendants first, and for siblings in their order in the children list)

Parameters:

Name Type Description
node ve.Node

The node that has been detached

Inherited from:
Source:
A node has been detached with ve.Node#setDocument .