当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Delta.retain方法代码示例

本文整理汇总了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;
 }
开发者ID:jacwright,项目名称:typewriter,代码行数:7,代码来源:decorators.ts

示例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;
  }
开发者ID:jacwright,项目名称:typewriter,代码行数:21,代码来源:decorators.ts

示例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;
 }
开发者ID:jacwright,项目名称:typewriter,代码行数:6,代码来源:decorators.ts

示例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 (&nbsp;) 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 = {};
      }
    }
  }
//.........这里部分代码省略.........
开发者ID:jacwright,项目名称:typewriter,代码行数:101,代码来源:delta-dom.ts


注:本文中的@typewriter/editor.Delta.retain方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。