本文整理匯總了TypeScript中@ephox/dom-globals.Range.setEnd方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Range.setEnd方法的具體用法?TypeScript Range.setEnd怎麽用?TypeScript Range.setEnd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@ephox/dom-globals.Range
的用法示例。
在下文中一共展示了Range.setEnd方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: TreeWalker
const moveEndPoint = (dom, rng: Range, node, start: boolean): void => {
const root = node, walker = new TreeWalker(node, root);
const nonEmptyElementsMap = dom.schema.getNonEmptyElements();
do {
// Text node
if (node.nodeType === 3 && Tools.trim(node.nodeValue).length !== 0) {
if (start) {
rng.setStart(node, 0);
} else {
rng.setEnd(node, node.nodeValue.length);
}
return;
}
// BR/IMG/INPUT elements but not table cells
if (nonEmptyElementsMap[node.nodeName] && !/^(TD|TH)$/.test(node.nodeName)) {
if (start) {
rng.setStartBefore(node);
} else {
if (node.nodeName === 'BR') {
rng.setEndBefore(node);
} else {
rng.setEndAfter(node);
}
}
return;
}
// Found empty text block old IE can place the selection inside those
if (Env.ie && Env.ie < 11 && dom.isBlock(node) && dom.isEmpty(node)) {
if (start) {
rng.setStart(node, 0);
} else {
rng.setEnd(node, 0);
}
return;
}
} while ((node = (start ? walker.next() : walker.prev())));
// Failed to find any text node or other suitable location then move to the root of body
if (root.nodeName === 'BODY') {
if (start) {
rng.setStart(root, 0);
} else {
rng.setEnd(root, root.childNodes.length);
}
}
};
示例2: tryFindRangePosition
const setEndPoint = (dom: DOMUtils, start: boolean, bookmark: PathBookmark, rng: Range) => {
const point = bookmark[start ? 'start' : 'end'];
let i, node, offset, children;
const root = dom.getRoot();
if (point) {
offset = point[0];
// Find container node
for (node = root, i = point.length - 1; i >= 1; i--) {
children = node.childNodes;
if (padEmptyCaretContainer(root, node, rng)) {
return true;
}
if (point[i] > children.length - 1) {
if (padEmptyCaretContainer(root, node, rng)) {
return true;
}
return tryFindRangePosition(node, rng);
}
node = children[point[i]];
}
// Move text offset to best suitable location
if (node.nodeType === 3) {
offset = Math.min(point[0], node.nodeValue.length);
}
// Move element offset to best suitable location
if (node.nodeType === 1) {
offset = Math.min(point[0], node.childNodes.length);
}
// Set offset within container node
if (start) {
rng.setStart(node, offset);
} else {
rng.setEnd(node, offset);
}
}
return true;
};
示例3:
Options.liftN([nextText, lastChild.filter(Node.isText)], (next: Element, end: Element) => {
const oldLength = end.dom().length;
end.dom().appendData(next.dom().data);
rng.setEnd(end.dom(), oldLength);
Remove.remove(next);
});
示例4: shouldApplyToTrailingSpaces
const applyWordGrab = (editor: Editor, rng: Range): void => {
const r = ExpandRange.expandRng(editor, rng, [{ inline: true }], shouldApplyToTrailingSpaces(rng));
rng.setStart(r.startContainer, r.startOffset);
rng.setEnd(r.endContainer, r.endOffset);
editor.selection.setRng(rng);
};
示例5: function
function (normalizedRng) {
rng.setStart(normalizedRng.startContainer, normalizedRng.startOffset);
rng.setEnd(normalizedRng.endContainer, normalizedRng.endOffset);
return true;
}
示例6:
(pos) => {
rng.setStart(pos.container(), pos.offset());
rng.setEnd(pos.container(), pos.offset());
return true;
}
示例7: function
const setContentEditableSelection = function (range: Range, forward?: boolean) {
let node;
const $ = editor.$;
const dom = editor.dom;
let $realSelectionContainer, sel,
startContainer, startOffset, endOffset, e, caretPosition, targetClone, origTargetClone;
if (!range) {
return null;
}
if (range.collapsed) {
if (!isRangeInCaretContainer(range)) {
if (forward === false) {
caretPosition = getNormalizedRangeEndPoint(-1, range);
if (isFakeCaretTarget(caretPosition.getNode(true))) {
return showCaret(-1, caretPosition.getNode(true), false, false);
}
if (isFakeCaretTarget(caretPosition.getNode())) {
return showCaret(-1, caretPosition.getNode(), !caretPosition.isAtEnd(), false);
}
} else {
caretPosition = getNormalizedRangeEndPoint(1, range);
if (isFakeCaretTarget(caretPosition.getNode())) {
return showCaret(1, caretPosition.getNode(), !caretPosition.isAtEnd(), false);
}
if (isFakeCaretTarget(caretPosition.getNode(true))) {
return showCaret(1, caretPosition.getNode(true), false, false);
}
}
}
return null;
}
startContainer = range.startContainer;
startOffset = range.startOffset;
endOffset = range.endOffset;
// Normalizes <span cE=false>[</span>] to [<span cE=false></span>]
if (startContainer.nodeType === 3 && startOffset === 0 && isContentEditableFalse(startContainer.parentNode)) {
startContainer = startContainer.parentNode;
startOffset = dom.nodeIndex(startContainer);
startContainer = startContainer.parentNode;
}
if (startContainer.nodeType !== 1) {
return null;
}
if (endOffset === startOffset + 1) {
node = startContainer.childNodes[startOffset];
}
if (!isContentEditableFalse(node)) {
return null;
}
targetClone = origTargetClone = node.cloneNode(true);
e = editor.fire('ObjectSelected', { target: node, targetClone });
if (e.isDefaultPrevented()) {
return null;
}
$realSelectionContainer = SelectorFind.descendant(SugarElement.fromDom(editor.getBody()), '#' + realSelectionId).fold(
function () {
return $([]);
},
function (elm) {
return $([elm.dom()]);
}
);
targetClone = e.targetClone;
if ($realSelectionContainer.length === 0) {
$realSelectionContainer = $(
'<div data-mce-bogus="all" class="mce-offscreen-selection"></div>'
).attr('id', realSelectionId);
$realSelectionContainer.appendTo(editor.getBody());
}
range = editor.dom.createRng();
// WHY is IE making things so hard! Copy on <i contentEditable="false">x</i> produces: <em>x</em>
// This is a ridiculous hack where we place the selection from a block over the inline element
// so that just the inline element is copied as is and not converted.
if (targetClone === origTargetClone && Env.ie) {
$realSelectionContainer.empty().append('<p style="font-size: 0" data-mce-bogus="all">\u00a0</p>').append(targetClone);
range.setStartAfter($realSelectionContainer[0].firstChild.firstChild);
range.setEndAfter(targetClone);
} else {
$realSelectionContainer.empty().append('\u00a0').append(targetClone).append('\u00a0');
range.setStart($realSelectionContainer[0].firstChild, 1);
range.setEnd($realSelectionContainer[0].lastChild, 0);
}
//.........這裏部分代碼省略.........