A utility for working around Ember-specific challenges when using ranges in an Ember app.
git clonethis repositorynpm installbower install
In an Ember app, the HTMLBars rendering library will insert metamorph tags into the DOM to track bindings. When doing low-level Range API manipulation, the presence of these tags can make it difficult to connect the positional information provided by the Range API to what the user actually sees on the screen.
This utility provides a way of getting useful Range information that is usually
obscured by the presence of metamorph tags by (perhaps foolishly) assuming nodes
that satisfy Node.nodeType === Node.TEXT_NODE && !node.textContent are
metamorphs.
A set of range-specific functions.
Tells the programmer if the start of the user's selection is visually in the first position of a given context.
Passing a context selector tells the function to stop checking whether the
selection is at the earliest possible position when it finds a matching element
as it traverses upwards in the DOM tree. This is useful if you want to see if
the selection is at the beginning of a .Line, for example.
import rangeUtils from 'ember-range/lib/range-utils';
rangeUtils.isFirstPosition('.Line');Tells the programmer if the start of the user's selection is visually in the last position of a given context.
Passing a context selector tells the function to stop checking whether the
selection is at the last possible position when it finds a matching element as
it traverses upwards in the DOM tree. This is useful if you want to see if the
selection is at the end of a .Line, for example.
import rangeUtils from 'ember-range/lib/range-utils';
rangeUtils.isLastPosition('.Line');A set of DOM-specific functions.
Returns an array of the non-metamorph children of a given node.
import domUtils from 'ember-range/lib/dom-utils';
domUtils.getNonMetamorphChildren(node);Tells the programmer if the given node is the first child in a given context. This function traverses upwards, and will return false if it reaches an ancestor of the node that is not the first non-metamorph child of its parent.
import domUtils from 'ember-range/lib/dom-utils';
domUtils.isFirstChild(node);Tells the programmer if the given node is the last child in a given context. This function traverses upwards, and will return false if it reaches an ancestor of the node that is not the last non-metamorph child of its parent.
import domUtils from 'ember-range/lib/dom-utils';
domUtils.isLastChild(node);ember testember test --server