Package org.waveprotocol.wave.model.document.operation.Nindo

Examples of org.waveprotocol.wave.model.document.operation.Nindo.Builder


  public void resetAnnotation(int start, int end, String key, String value) {
    Annotations.checkPersistentKey(key);
    Preconditions.checkPositionIndexes(start, end, doc.size());
    try {
      begin();
      Builder b = new Builder();
      if (start > 0) {
        b.startAnnotation(key, null);
        b.skip(start);
      }
      if (start != end) {
        b.startAnnotation(key, value);
        b.skip(end - start);
      }
      if (doc.size() != end) {
        b.startAnnotation(key, null);
        b.skip(doc.size() - end);
      }
      b.endAnnotation(key);
      consume(b.build());
    } finally {
      end();
    }
  }
View Full Code Here


  // Helper DSL methods for building operations
  // at() creates a builder with cursor at the given location
  // Each other method does something convenient and returns the given builder

  private Builder at(int location) {
    Builder b = new Builder();
    if (location > 0) {
      b.skip(location);
    }
    return b;
  }
View Full Code Here

  }

  private Builder deleteRangeInternal(int startLocation, int endLocation) {
    // TODO(danilatos): Delete this method when deleting is redone efficiently

    Builder builder = at(startLocation);
    Point<N> start = doc.locate(startLocation);
    Point<N> end = doc.locate(endLocation);

    assert doc.isSameNode(
        Point.enclosingElement(doc, start.getContainer()),
        Point.enclosingElement(doc, end.getContainer()))
        : "Range must be within a single element";

    N node;
    if (start.isInTextNode()) {
      if (doc.isSameNode(start.getContainer(), end.getContainer())) {
        int size = end.getTextOffset() - start.getTextOffset();
        if (size > 0) {
          builder.deleteCharacters(size);
        }
        return builder;
      } else {
        int size = doc.getLength(doc.asText(start.getContainer())) - start.getTextOffset();
        node = doc.getNextSibling(start.getContainer());
        if (size > 0) {
          builder.deleteCharacters(size);
        }
      }
    } else {
      node = start.getNodeAfter();
    }

    N stop;
    if (end.isInTextNode()) {
      stop = end.getContainer();
    } else {
      stop = end.getNodeAfter();
    }

    while (node != stop) {
      N next = doc.getNextSibling(node);
      T text = doc.asText(node);
      if (text != null) {
        builder.deleteCharacters(doc.getData(text).length());
      } else {
        deleteElement(doc.asElement(node), builder);
      }
      node = next;
    }

    if (end.isInTextNode()) {
      int size = end.getTextOffset();
      if (size > 0) {
        builder.deleteCharacters(size);
      }
    }

    return builder;
  }
View Full Code Here

TOP

Related Classes of org.waveprotocol.wave.model.document.operation.Nindo.Builder

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.