本文整理匯總了TypeScript中@typewriter/editor.Delta.retain方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Delta.retain方法的具體用法?TypeScript Delta.retain怎麽用?TypeScript Delta.retain使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@typewriter/editor.Delta
的用法示例。
在下文中一共展示了Delta.retain方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: line
line(at: number, attributes: { [name: string]: any }) {
const line = this.contents.getLines(at, at)[0];
if (!line) return;
this.updatePosition(line.end - 1);
this.delta.retain(1, { decorator: attributes });
this.position += 1;
}
示例2: updatePosition
private updatePosition(from: number, to?: number): any {
if (this.change) {
from = this.change.transformPosition(from);
if (to != null) to = this.change.transformPosition(to);
}
// Optimize by adding to the existing delta when possible, compose is slow
if (this.position < from) {
this.delta.retain(from - this.position);
this.position = from;
} else if (this.position) {
this.change = this.getChange();
from = this.change.transformPosition(from);
if (to != null) to = this.change.transformPosition(to);
this.delta = new Delta();
this.delta.retain(from);
this.position = from;
}
return to != null ? [ from, to ] : from;
}
示例3: mark
mark(from: number, to: number, attributes: { [name: string]: any }) {
[ from, to ] = this.updatePosition(from, to);
const length = to - from;
this.delta.retain(length, { decorator: attributes });
this.position += length;
}
示例4: deltaFromDom
export function deltaFromDom(root: Element, paper: Paper, options: any = {}) {
const inDom = root.ownerDocument.contains(root);
const { blocks, marks, embeds } = paper;
if (!options) options = defaultOptions;
var walker = root.ownerDocument.createTreeWalker(root, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, {
acceptNode: node => {
if (SKIP_ELEMENTS[node.nodeName]) {
return NodeFilter.FILTER_REJECT;
} else if (node.nodeType === Node.TEXT_NODE && node.nodeValue === '') {
node.nodeType === Node.TEXT_NODE;
} else if (node.nodeType === Node.TEXT_NODE || options.notInDom || inDom) {
return NodeFilter.FILTER_ACCEPT;
} else {
return NodeFilter.FILTER_REJECT;
}
}
});
const delta = new Delta();
let currentBlock: any, firstBlockSeen = false, unknownBlock = false, empty = true, node: Node;
let lastNode = false;
if (options.startNode) {
walker.currentNode = options.startNode;
walker.previousNode();
if (options.offset) delta.retain(options.offset, undefined);
} else {
walker.currentNode = root;
}
while ((node = walker.nextNode())) {
if (node === options.endNode) lastNode = true;
else if (lastNode) break;
if (isBRPlaceholder(paper, node)) {
empty = false;
} else if (node.nodeType === Node.TEXT_NODE) {
let parent = node.parentNode as Element;
// If all newlines, we can ignore
if (node.nodeValue.replace(/\n+/g, '') === '') continue;
// non-breaking spaces ( ) are spaces in a delta
const text = node.nodeValue.replace(/\xA0/g, ' ').replace(/\n+/g, ' ');
// Word gives us end-of-paragraph nodes with a single space. Ignore them.
if (!text || (text === ' ' && parent.classList.contains('EOP'))) continue;
// Gather up all the marks for this text node, walking up to the block level
const attributes = gatherMarks(parent, root, paper);
empty = false;
delta.insert(text, attributes);
} else if (node.className.indexOf('decorator') !== -1) {
continue;
} else if (embeds.matches(node)) {
const embed = embeds.findByNode(node);
if (embed) {
const attributes = gatherMarks(node.parentNode as Element, root, paper);
delta.insert(embed.fromDom ? embed.fromDom(node, paper) : { [embed.name]: true }, attributes);
}
} else if (blocks.matches(node) || (node.nodeType === Node.ELEMENT_NODE && (node as Element).matches(BLOCK_ELEMENTS))) {
unknownBlock = !blocks.matches(node);
if (unknownBlock) {
let parent = node.parentNode;
while (parent && !blocks.matches(parent) && parent !== root) {
parent = parent.parentNode;
}
// If this block element is inside a recognized block, ignore it
if (parent && parent !== root) {
continue;
}
}
const block = blocks.findByNode(node, true);
// Skip paragraphs/divs inside blockquotes and list items etc.
if (block === blocks.getDefault() && blocks.matches(node.parentNode)) {
continue;
}
if (firstBlockSeen) {
if (!currentBlock.unknownBlock || !empty) {
delta.insert('\n', currentBlock.unknownBlock ? {} : currentBlock);
empty = true;
}
} else {
firstBlockSeen = true;
}
if (unknownBlock) {
currentBlock = { unknownBlock };
} else if (block !== blocks.getDefault()) {
currentBlock = block.fromDom ? block.fromDom(node, paper) : { [block.name]: true };
} else {
currentBlock = {};
}
}
}
//.........這裏部分代碼省略.........