Package org.waveprotocol.wave.model.document.util

Examples of org.waveprotocol.wave.model.document.util.Range


  /**
   * @param editorDiv
   * @return end selection of editor owning doc div
   */
  public static int webdriverEditorGetEndSelection(Element editorDiv) {
    Range range = getSelectionWithFlush(editorDiv);
    return range == null ? -1 : range.getEnd();
  }
View Full Code Here


   * @param editor Contains the non-null selection and document
   * @param keys Keys to look through
   * @return The first value annotation that covers the range at one of the given keys, else null.
   */
  public static String getFirstAnnotationOverSelection(EditorContext editor, String... keys) {
    Range range = Preconditions.checkNotNull(
        editor.getSelectionHelper().getSelectionRange(), "Editor must have selection").asRange();

    return getFirstCoveringAnnotationOverRange(editor.getDocument(), editor.getCaretAnnotations(),
        keys, range.getStart(), range.getEnd());
  }
View Full Code Here

   *
   * @param editor Editor whose annotations are to be checked, with non-null selection and doc.
   * @param key Key of annotation to retrieve
   */
  public static String getAnnotationOverSelectionIfFull(EditorContext editor, String key) {
    Range range = Preconditions.checkNotNull(
        editor.getSelectionHelper().getSelectionRange(), "Editor must have selection").asRange();

    return getAnnotationOverRangeIfFull(editor.getDocument(), editor.getCaretAnnotations(),
        key, range.getStart(), range.getEnd());
  }
View Full Code Here

   * @param editor Editor to set the annotation, with non-null selection and doc.
   * @param key Annotation key to set.
   * @param value Annotation value to set key to.
   */
  public static void setAnnotationOverSelection(EditorContext editor, String key, String value) {
    Range range = Preconditions.checkNotNull(
        editor.getSelectionHelper().getSelectionRange(), "Editor must have selection").asRange();

    setAnnotationOverRange(editor.getDocument(), editor.getCaretAnnotations(),
        key, value, range.getStart(), range.getEnd());
  }
View Full Code Here

   * @param editor Editor whose annotations are to be cleared, with non-null selection and doc.
   * @param keys List of annotation keys to clear
   * @return true if annotations were actually changed
   */
  public static boolean clearAnnotationsOverSelection(EditorContext editor, String... keys) {
    Range range = Preconditions.checkNotNull(
        editor.getSelectionHelper().getSelectionRange(), "Editor must have selection").asRange();

    return clearAnnotationsOverRange(editor.getDocument(), editor.getCaretAnnotations(),
        keys, range.getStart(), range.getEnd());
  }
View Full Code Here

    int start = doc.lastAnnotationChange(0, location, key, value);
    int end = doc.firstAnnotationChange(location, doc.size(), key, value);

    assert start < end : "Range should not be collapsed";

    return new Range(start, end);
  }
View Full Code Here

          current = CursorDirection.FROM_LEFT;
        }

        FocusedRange focused = getSelectionHelper().getSelectionRange();
        if (focused != null) {
          Range range = focused.asRange();
          currentSelectionBias = annotationLogic.rebias(range.getStart(), range.getEnd(), current);
        } else {
          // no selection, so have default bias
          currentSelectionBias = BiasDirection.LEFT;
        }
      }
View Full Code Here

   */
  public XmlStringBuilder renderRange(Point<N> start, Point<N> end) {
    N nearestCommonAncestor =
        DocHelper.nearestCommonAncestor(doc, start.getCanonicalNode(), end.getCanonicalNode());

    Range inclusion = new Range(doc.getLocation(start), doc.getLocation(end));

    XmlStringBuilder builder =
      XmlStringBuilder.createEmptyWithCharConstraints(PermittedCharacters.BLIP_TEXT);

    E asElement = doc.asElement(nearestCommonAncestor);
    if (asElement != null) {
      for (N child = doc.getFirstChild(asElement);
           child != null; child = doc.getNextSibling(child)) {
        builder.append(augmentBuilder(child, inclusion));
      }
      if (asElement != doc.getDocumentElement()
          && shouldInclude(inclusion, getNodeRange(asElement))) {
        builder.wrap(doc.getTagName(asElement),
            CollectionUtils.adaptStringMap(doc.getAttributes(asElement)));
      }
    } else {
      T asText = doc.asText(nearestCommonAncestor);
      int tStart = doc.getLocation(asText);
      String substring =
          doc.getData(asText).substring(inclusion.getStart() - tStart, inclusion.getEnd() - tStart);

      builder.appendText(substring);
    }
    return builder;
  }
View Full Code Here

    }
    return builder;
  }

  private XmlStringBuilder augmentBuilder(N node, Range inclusion) {
    Range nodeRange = getNodeRange(node);
    XmlStringBuilder builder = XmlStringBuilder.createEmpty();

    if (!shouldInclude(inclusion, nodeRange)) {
      return builder;
    }
View Full Code Here

  }

  private Range getNodeRange(N node) {
    assert node != null && node != doc.getDocumentElement() :
      "Node cannot be null or the document element";
    Range r = new Range(doc.getLocation(node), getNodeEnd(node));
    return r;
  }
View Full Code Here

TOP

Related Classes of org.waveprotocol.wave.model.document.util.Range

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.