本文整理匯總了TypeScript中@ephox/sugar.Traverse.prevSibling方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Traverse.prevSibling方法的具體用法?TypeScript Traverse.prevSibling怎麽用?TypeScript Traverse.prevSibling使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@ephox/sugar.Traverse
的用法示例。
在下文中一共展示了Traverse.prevSibling方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
Traverse.lastChild(elm).each(function (lastChild) {
Traverse.prevSibling(lastChild).each(function (lastChildPrevSibling) {
if (ElementType.isBlock(elm) && ElementType.isBr(lastChild) && ElementType.isBlock(lastChildPrevSibling)) {
Remove.remove(lastChild);
}
});
});
示例2: function
const deleteNormalized = function (elm, afterDeletePosOpt) {
return Options.liftN([Traverse.prevSibling(elm), Traverse.nextSibling(elm), afterDeletePosOpt], function (prev, next, afterDeletePos) {
let offset;
const prevNode = prev.dom();
const nextNode = next.dom();
if (NodeType.isText(prevNode) && NodeType.isText(nextNode)) {
offset = prevNode.data.length;
prevNode.appendData(nextNode.data);
Remove.remove(next);
Remove.remove(elm);
if (afterDeletePos.container() === nextNode) {
return new CaretPosition(prevNode, offset);
} else {
return afterDeletePos;
}
} else {
Remove.remove(elm);
return afterDeletePos;
}
}).orThunk(function () {
Remove.remove(elm);
return afterDeletePosOpt;
});
};
示例3: function
function (child) {
if (Node.name(child) === 'br') {
return Traverse.prevSibling(child).map(function (sibling) {
return [node].concat(getLastChildren(sibling));
}).getOr([]);
} else {
return [node].concat(getLastChildren(child));
}
}
示例4: CaretPosition
const deleteNormalized = (elm: Element, afterDeletePosOpt: Option<CaretPosition>, normalizeWhitespace?: boolean): Option<CaretPosition> => {
const prevTextOpt = Traverse.prevSibling(elm).filter((e) => NodeType.isText(e.dom()));
const nextTextOpt = Traverse.nextSibling(elm).filter((e) => NodeType.isText(e.dom()));
// Delete the element
Remove.remove(elm);
// Merge and normalize any prev/next text nodes, so that they are merged and don't lose meaningful whitespace
// eg. <p>a <span></span> b</p> -> <p>a &nsbp;b</p> or <p><span></span> a</p> -> <p> a</a>
return Options.liftN([ prevTextOpt, nextTextOpt, afterDeletePosOpt ], (prev, next, pos) => {
const prevNode = prev.dom(), nextNode = next.dom();
const offset = prevNode.data.length;
MergeText.mergeTextNodes(prevNode, nextNode, normalizeWhitespace);
// Update the cursor position if required
return pos.container() === nextNode ? CaretPosition(prevNode, offset) : pos;
}).orThunk(() => {
if (normalizeWhitespace) {
prevTextOpt.each((elm) => MergeText.normalizeWhitespaceBefore(elm.dom(), elm.dom().length));
nextTextOpt.each((elm) => MergeText.normalizeWhitespaceAfter(elm.dom(), 0));
}
return afterDeletePosOpt;
});
};
示例5: function
const getPrevLast = function (last) {
return Traverse.prevSibling(last).bind(function (prevLast) {
return checkLast(prevLast) ? Option.some(prevLast) : getPrevLast(prevLast);
});
};