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


TypeScript dom-globals.Range类代码示例

本文整理汇总了TypeScript中@ephox/dom-globals.Range的典型用法代码示例。如果您正苦于以下问题:TypeScript Range类的具体用法?TypeScript Range怎么用?TypeScript Range使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Range类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: setTimeout

const fallback = (editor: Editor): FallbackFn => (html, done) => {
  const markedHtml = InternalHtml.mark(html);
  const outer = editor.dom.create('div', {
    'contenteditable': 'false',
    'data-mce-bogus': 'all'
  });
  const inner = editor.dom.create('div', { contenteditable: 'true' }, markedHtml);
  editor.dom.setStyles(outer, {
    position: 'fixed',
    top: '0',
    left: '-3000px',
    width: '1000px',
    overflow: 'hidden'
  });
  outer.appendChild(inner);
  editor.dom.add(editor.getBody(), outer);

  const range = editor.selection.getRng();
  inner.focus();

  const offscreenRange: Range = editor.dom.createRng();
  offscreenRange.selectNodeContents(inner);
  editor.selection.setRng(offscreenRange);

  setTimeout(() => {
    editor.selection.setRng(range);
    outer.parentNode.removeChild(outer);
    done();
  }, 0);
};
开发者ID:danielpunkass,项目名称:tinymce,代码行数:30,代码来源:CutCopy.ts

示例2: prependData

const rngSetContent = (rng: Range, fragment: DocumentFragment): void => {
  const firstChild = Option.from(fragment.firstChild).map(Element.fromDom);
  const lastChild = Option.from(fragment.lastChild).map(Element.fromDom);

  rng.deleteContents();
  rng.insertNode(fragment);

  const prevText = firstChild.bind(Traverse.prevSibling).filter(Node.isText).bind(removeEmpty);
  const nextText = lastChild.bind(Traverse.nextSibling).filter(Node.isText).bind(removeEmpty);

  // Join start
  Options.liftN([prevText, firstChild.filter(Node.isText)], (prev: Element, start: Element) => {
    prependData(start.dom(), prev.dom().data);
    Remove.remove(prev);
  });

  // Join end
  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);
  });

  rng.collapse(false);
};
开发者ID:tinymce,项目名称:tinymce,代码行数:26,代码来源:SetSelectionContent.ts

示例3: createRange

 .map(function (newEndPos) {
   if (!CaretUtils.isInSameBlock(startPos, endPos, rootNode) && CaretUtils.isInSameBlock(startPos, newEndPos, rootNode)) {
     return createRange(startPos.container(), startPos.offset(), newEndPos.container(), newEndPos.offset());
   } else {
     return rng;
   }
 }).getOr(rng);
开发者ID:danielpunkass,项目名称:tinymce,代码行数:7,代码来源:RangeNormalizer.ts

示例4: function

const moveStart = function (dom: DOMUtils, selection: Selection, rng: Range) {
  const offset = rng.startOffset;
  let container = rng.startContainer, walker, node, nodes;

  if (rng.startContainer === rng.endContainer) {
    if (isInlineBlock(rng.startContainer.childNodes[rng.startOffset])) {
      return;
    }
  }

  // Move startContainer/startOffset in to a suitable node
  if (container.nodeType === 1) {
    nodes = container.childNodes;
    if (offset < nodes.length) {
      container = nodes[offset];
      walker = new TreeWalker(container, dom.getParent(container, dom.isBlock));
    } else {
      container = nodes[nodes.length - 1];
      walker = new TreeWalker(container, dom.getParent(container, dom.isBlock));
      walker.next(true);
    }

    for (node = walker.current(); node; node = walker.next()) {
      if (node.nodeType === 3 && !isWhiteSpaceNode(node)) {
        rng.setStart(node, 0);
        selection.setRng(rng);

        return;
      }
    }
  }
};
开发者ID:danielpunkass,项目名称:tinymce,代码行数:32,代码来源:FormatUtils.ts

示例5: 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;
};
开发者ID:danielpunkass,项目名称:tinymce,代码行数:47,代码来源:ResolveBookmark.ts

示例6: 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);
    }
  }
};
开发者ID:danielpunkass,项目名称:tinymce,代码行数:52,代码来源:SelectionUtils.ts

示例7: getNodeRange

const selectNode = (editor, node: Element): Range => {
  const e = editor.fire('BeforeObjectSelected', { target: node });
  if (e.isDefaultPrevented()) {
    return null;
  }

  return getNodeRange(node);
};
开发者ID:danielpunkass,项目名称:tinymce,代码行数:8,代码来源:CefUtils.ts

示例8: createRange

  const toRange = (): Range => {
    let range;

    range = createRange(container.ownerDocument);
    range.setStart(container, offset);
    range.setEnd(container, offset);

    return range;
  };
开发者ID:danielpunkass,项目名称:tinymce,代码行数:9,代码来源:CaretPosition.ts

示例9: trimEmptyTextNode

const deleteContentAndShowCaret = (editor: Editor, range: Range, node: Node, direction: HDirection, forward: boolean, peekCaretPosition: CaretPosition) => {
  const caretRange = CefUtils.showCaret(direction, editor, peekCaretPosition.getNode(!forward) as Element, forward, true);
  // Delete the selected content
  if (range.collapsed) {
    const deleteRange = range.cloneRange();
    if (forward) {
      deleteRange.setEnd(caretRange.startContainer, caretRange.startOffset);
    } else {
      deleteRange.setStart(caretRange.endContainer, caretRange.endOffset);
    }
    deleteRange.deleteContents();
  } else {
    range.deleteContents();
  }
  editor.selection.setRng(caretRange);
  trimEmptyTextNode(editor.dom, node);
  return true;
};
开发者ID:tinymce,项目名称:tinymce,代码行数:18,代码来源:CefBoundaryDelete.ts

示例10: trimEmptyTextNode

const insertFragment = (dom: DOMUtils, rng: Range, frag: DocumentFragment) => {
  const firstChild = Option.from(frag.firstChild);
  const lastChild = Option.from(frag.lastChild);

  rng.insertNode(frag);

  firstChild.each((child) => trimEmptyTextNode(dom, child.previousSibling));
  lastChild.each((child) => trimEmptyTextNode(dom, child.nextSibling));
};
开发者ID:danielpunkass,项目名称:tinymce,代码行数:9,代码来源:RangeInsertNode.ts


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