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


TypeScript Range.setStart方法代码示例

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


在下文中一共展示了Range.setStart方法的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);
    }
  }
};
开发者ID:danielpunkass,项目名称:tinymce,代码行数:52,代码来源:SelectionUtils.ts

示例2: 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

示例3: 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

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

示例5: function

 function (normalizedRng) {
   rng.setStart(normalizedRng.startContainer, normalizedRng.startOffset);
   rng.setEnd(normalizedRng.endContainer, normalizedRng.endOffset);
   return true;
 }
开发者ID:danielpunkass,项目名称:tinymce,代码行数:5,代码来源:RangeUtils.ts

示例6:

 (pos) => {
   rng.setStart(pos.container(), pos.offset());
   rng.setEnd(pos.container(), pos.offset());
   return true;
 }
开发者ID:danielpunkass,项目名称:tinymce,代码行数:5,代码来源:ResolveBookmark.ts

示例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);
    }
//.........这里部分代码省略.........
开发者ID:danielpunkass,项目名称:tinymce,代码行数:101,代码来源:SelectionOverrides.ts


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