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

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


    // By default, we will look for link keys.
    // TODO(user): Refactor this to not assume that we are interested
    // in just links.
    // Find range that covers contentElement and the annotation.
    for (String key : Link.LINK_KEYS) {
      Range range = AnnotationHelper.getRangePrecedingElement(doc, contentElement, key);
      if (range != null) {
        return range;
      }
    }
    return null;
View Full Code Here


  @Override
  public void populateSuggestionMenu(final Menu menu) {
    // Some suggestions will replace the annotated range (links), if one is found,
    // track it to be passed along to the suggestion menu.
    Range replaceRange = findLinkAnnotationRange(contentElement.getMutableDoc(), contentElement);
    if (replaceRange != null) {
      replacementRangeHelper.trackRange(replaceRange);
    }
    Menu menuWrapper = new Menu() {
      @Override
View Full Code Here

          if (slash == i - 1) {
            loc++;
          }
          break;
        case '|':
          selection = new Range(loc);
          return;
        case '[':
          start = loc--;
          break;
        case ']':
          selection = new Range(start, loc);
          return;
      }
    }
  }
View Full Code Here

    replaceWithGadget(gadgetUrl, params);
  }

  /** Replaces the contentElement with a gadget. */
  private void replaceWithGadget(String url, StateMap stateMap) {
    Range range = replacementRangeProvider.getRange();
    if (range == null) {
      return;
    }

    // NOTE(user): Clear the annotation to schedule repaint. Is there a better
    // way?
    doc.setAnnotation(range.getStart(), range.getEnd(), keyToClear, null);
    doc.deleteRange(doc.locate(range.getStart()), doc.locate(range.getEnd()));

    // TODO: Plumb the login name here
    doc.insertXml(doc.locate(range.getStart()),
        GadgetXmlUtil.constructXml(url, stateMap, "anonymous@example.com" /* Fix this */));
  }
View Full Code Here

  @VisibleForTesting
  void writeSelection(MutableAnnotationSet.Persistent document, FocusedRange selection,
      String compositionState, double currentTimeMillis) {
    // TODO(danilatos): Use focus and not end
    Range range = selection == null ? null : selection.asRange();
    String rangeKey = SelectionAnnotationHandler.rangeKey(sessionId);
    String endKey = SelectionAnnotationHandler.endKey(sessionId);
    String dataKey = SelectionAnnotationHandler.dataKey(sessionId);
    String value = address;

    int size = document.size();

    // If we have a selection, then continually update regardless of old value,
    // to refresh the timestamp.
    if (range != null) {
      document.setAnnotation(0, size, dataKey, address + "," + currentTimeMillis + ","
          + (compositionState != null ? compositionState : ""));
    }

    // TODO(danilatos): This fiddliness is necessary to avoid gratuitous
    // re-rendering.
    // Later the code can just use the resetAnnotation method, which will be
    // MUCH
    // simpler, once we have proper fine-granularity notifications.
    int currentFocus = document.firstAnnotationChange(0, size, endKey, null);
    int currentEnd = document.lastAnnotationChange(0, size, rangeKey, null);
    if (currentEnd == -1) {
      currentEnd = currentFocus;
    }
    if (currentEnd != -1) {
      // if old selection is annotated
      int currentStart = document.firstAnnotationChange(0, size, rangeKey, null);
      if (currentStart == -1 || currentStart > currentEnd) {
        currentStart = currentEnd;
      }
      if (range != null) {
        // if new selection exists
        int newStart = range.getStart();
        int newEnd = range.getEnd();
        int newFocus = selection.getFocus();

        if (newFocus < currentFocus) {
          document.setAnnotation(newFocus, currentFocus, endKey, value);
        } else if (newFocus > currentFocus) {
          document.setAnnotation(currentFocus, newFocus, endKey, null);
        }

        if (currentStart >= newEnd || newStart >= currentEnd) {
          // If not overlapping
          document.setAnnotation(currentStart, currentEnd, rangeKey, null);
          document.setAnnotation(newStart, newEnd, rangeKey, value);
        } else {
          // If overlapping

          if (currentStart < newStart) {
            document.setAnnotation(currentStart, newStart, rangeKey, null);
          } else if (currentStart > newStart) {
            document.setAnnotation(newStart, currentStart, rangeKey, value);
          }
          if (currentEnd < newEnd) {
            document.setAnnotation(currentEnd, newEnd, rangeKey, value);
          } else if (currentEnd > newEnd) {
            document.setAnnotation(newEnd, currentEnd, rangeKey, null);
          }
        }
      } else {
        // no new selection, clear old one
        document.setAnnotation(currentFocus, size, endKey, null);
        document.setAnnotation(currentStart, currentEnd, rangeKey, null);
        document.setAnnotation(0, size, dataKey, null);
      }
    } else {
      // no old selection
      if (range != null) {
        // new selection exists
        document.setAnnotation(selection.getFocus(), size, endKey, value);
        document.setAnnotation(range.getStart(), range.getEnd(), rangeKey, value);
      }
    }
  }
View Full Code Here

  @Override
  public Range deleteRange(int start, int end) {
    Preconditions.checkPositionIndexes(start, end, size());
    // TODO(davidbyttow/danilatos): Handle this more efficiently.
    PointRange<N> range = deleteRange(doc.locate(start), doc.locate(end));
    return new Range(doc.getLocation(range.getFirst()), doc.getLocation(range.getSecond()));
  }
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.