Module: Editing

Editing

Source:

Methods

<inner> ascendWalkSiblings(ascendNodes, atEnd, carryDown)

Walks the siblings of each node in the given array (see walkSiblings()).
Parameters:
Name Type Description
ascendNodes from lowest descendant to topmost parent. The topmost parent and its siblings will not be walked over.
atEnd indicates that the position to ascend from is not at ascendNodes[0], but at the end of ascendNodes[0] (meaning that all of ascendNodes[0]'s children will be walked over as well).
carryDown is invoked on each node in the given array, allowing the carrying down of a context value. May return null to return the carryDown value from above.
Source:

<inner> break_(liveRange, breaker, linebreak) → {Array.<Boundary>}

Creates a visual line break at the end position of the given range.
Parameters:
Name Type Description
liveRange Range
breaker string
linebreak boolean
Source:
Returns:
Type
Array.<Boundary>

<inner> delete_(range) → {Array.<Boundary>}

Removes the content inside the given range. “If you delete a paragraph-boundary, the result seems to be consistent: The leftmost block 'wins', and the content of the rightmost block is included in the leftmost:

Overskrift

[]Text

“If delete is pressed, this is the result:

Overskrift[]Text

” -- http://dev.opera.com/articles/view/rich-html-editing-in-the-browser-part-1 TODO: put   at beginning and end position in order to preserve spaces at these locations when deleting. also consider propping

's
Parameters:
Name Type Description
range Range
Source:
See:
Returns:
Type
Array.<Boundary>

<inner> format(styleName, opts)

Ensures the given range is wrapped by elements that have a given CSS style set.
Parameters:
Name Type Description
styleName a CSS style name. Please note that not-inherited styles currently may (or may not) cause undesirable results. See also Html.isStyleInherited(). The underline style can't be unformatted inside a non-clearable ancestor ("text-decoration: none" doesn't do anything as the underline will be drawn by the ancestor).
opts all options supported by wrapElem() as well as the following: createWrapper - a function that takes a style value and returns a new empty wrapper node that has the style value applied. isPrunable - a function that returns true if a given node, after some style was removed from it, can be removed entirely. That's usually the case if the given node is equivalent to an empty wrapper. isStyleEqual - a function that returns true if two given style values are equal. TODO currently we just use strict equals by default, but we should implement for each supported style it's own equals function.
Source:

<inner> mutate(liveRange, formatter)

Walks around the boundary of range and invokes the given functions with the nodes it encounters. clearOverride - invoked for partially contained nodes. clearOverrideRec - invoked for top-level contained nodes. pushDownOverride - invoked for left siblings of ancestors of startContainer[startOffset], and for right siblings of ancestors of endContainer[endOffset]. setContext - invoked for top-level contained nodes. The purpose of the walk is to either push-down or set a context on all nodes within the range, and push-down any overrides that exist along the bounderies of the range. An override is a context that overrides the context to set. Pushing-down a context means that an existing context-giving ancestor element will be reused, if available, and setContext() will not be invoked. Pushing-down an override means that ancestors of the range's start or end containers will have their overrides cleared and the subset of the ancestors' children that is not contained by the range will have the override applied via pushDownOverride(). This algorithm will not by itself mutate anything, or depend on any mutations by the given functions. clearOverride, clearOverideRec, setContext, pushDownContext may mutate the given node and it's previous siblings, and may insert nextSiblings, but must not mutate the next sibling of the given node, and must return the nextSibling of the given node (the nextSibling before any mutations). When setContext is invoked with hasOverrideAncestor, it is for example when a bold element is at the same time the upper boundary (for example when the bold element itself is the editing host) and an attempt is made to set a non-bold context inside the bold element. To work around this, setContext() could force a non-bold context by wrapping the node with a . See hasOverrideAncestor below.
Parameters:
Name Type Description
liveRange range's boundary points should be between nodes (Mutation.splitTextContainers).
formatter a map with the following properties isUpperBoundary(node) - identifies exclusive upper boundary element, only elements below which will be modified. getOverride(node) - returns a node's override, or null/undefined if the node does not provide an override. The topmost node for which getOverride returns a non-null value is the topmost override. If there is a topmost override, and it is below the upper boundary element, it will be cleared and pushed down. Should return a non-null value for any node for which hasContext(node) returns true. clearOverride(node) - should clear the given node of an override. The given node may or may not have an override set. Will be invoked shallowly for all ancestors of start and end containers (up to isUpperBoundary or hasContext). May perform mutations as explained above. clearOverrideRec(node) - like clearOverride but should clear the override recursively. If not provided, clearOverride will be applied recursively. pushDownOverride(node, override) - applies the given override to node. Should check whether the given node doesn't already provide its own override, in which case the given override should not be applied. May perform mutations as explained above. hasContext(node) - returns true if the given node already provides the context to set. setContext(node, override, hasOverrideAncestor) - applies the context to the given node. Should clear overrides recursively. Should also clear context recursively to avoid unnecessarily nested contexts. hasOverrideAncestor is true if an override is in effect above the given node (see explanation above). May perform mutations as explained above.
Source:

<inner> normalizeBoundary(point) → {Boolean}

Tries to move the given boundary to the start of line, skipping over any unrendered nodes, or if that fails to the end of line (after a br element if present), and for the last line in a block, to the very end of the block. If the selection is inside a block with only a single empty line (empty except for unrendered nodes), and both boundary points are normalized, the selection will be collapsed to the start of the block. For some operations it's useful to think of a block as a number of lines, each including its respective br and any preceding unrendered whitespace and in case of the last line, also any following unrendered whitespace.
Parameters:
Name Type Description
point Cursor
Source:
Returns:
True if the cursor is moved.
Type
Boolean

<inner> pushDownContext()

Pushes down an implied context above or at pushDownFrom to the given range by clearing all overrides from pushDownFrom (inclusive) to range.commonAncestorContainer, and clearing all overrides inside and along the range's boundary (see walkBoundaryInsideOutside()), invoking pushDownOverride on all siblings of the range boundary that are not contained in it. Requires range's boundary points to be between nodes (Mutation.splitTextContainers).
Source:

<inner> split(liveRange)

Splits the ancestors above the given range's start and end points.
Parameters:
Name Type Description
liveRange
Source:

<inner> trimExpandBoundaries()

Ensures that the given boundaries are neither in start nor end positions. In other words, after this operation, both will have preceding and following siblings. Expansion/trimming can be controlled via expandUntil and trimUntil, but may cause one or both of the boundaries to remain in start or end position.
Source:

<inner> walkBoundaryInsideOutside()

Simplifies walkBoundaryLeftRightInbetween from left/right/inbetween to just inside/outside. Requires range's boundary points to be between nodes (Mutation.splitTextContainers).
Source:

<inner> walkBoundaryLeftRightInbetween()

Walks the boundary of the range. The range's boundary starts at startContainer/startOffset, goes up to to the commonAncestorContainer's child above or equal startContainer/startOffset, continues to the commonAnestorContainer's child above or equal to endContainer/endOffset, and goes down again to endContainer/endOffset. Requires range's boundary points to be between nodes (Mutation.splitTextContainers).
Source:

<inner> walkSiblings()

Walks the siblings of the given child, calling before for siblings before the given child, after for siblings after the given child, and at for the given child.
Source:

<inner> wrapElem(liveRange, nodeName, remove, opts)

Ensures the given range is wrapped by elements with a given nodeName.
Parameters:
Name Type Description
liveRange Range The range of the current selection.
nodeName String The name of the tag that should serve as the wrapping node.
remove boolean Optional flag, which when set to false will cause the given markup to be removed (unwrapped) rather then set.
opts Object A map of options (all optional): createWrapper - a function that returns a new empty wrapper node to use. isReusable - a function that returns true if a given node, already in the DOM at the correct place, can be reused instead of creating a new wrapper node. May be merged with other reusable or newly created wrapper nodes.
Source: