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

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


  @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


    }
    if (currentAnnotation == null) {
      return null;
    }
    int start = doc.lastAnnotationChange(0, end, key, currentAnnotation);
    return new Range(start, end);
  }
View Full Code Here

    this.action = action;
  }

  @Override
  public void onClicked() {
    final Range range = editor.getSelectionHelper().getOrderedSelectionRange();
    if (range != null) {
      editor.undoableSequence(new Runnable(){
        @Override public void run() {
          LocationMapper<ContentNode> locator = editor.getDocument();
          Paragraph.traverse(locator, range.getStart(), range.getEnd(), action);
        }
      });
    }
  }
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

    // 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

    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

      return;
    }
    try {
      // We try to create a link with the current selection, if fails, we ask
      // for a link
      Range rg = range.asRange();
      String text = DocHelper.getText(editor.getDocument(), rg.getStart(), rg.getEnd());
      String linkAnnotationValue = Link.normalizeLink(text);
      EditorAnnotationUtil.setAnnotationOverSelection(editor, AnnotationConstants.LINK_PREFIX, linkAnnotationValue);
    } catch (InvalidLinkException e) {
      String rawLinkValue =
          Window.prompt(messages.enterLink(), WaveRefConstants.WAVE_URI_PREFIX);
View Full Code Here

    focusedRange = editor.getSelectionHelper().getSelectionRange();
    if (focusedRange == null) {
      Window.alert(ComplexColorPicker.messages.selectSomeText());
      return;
    }
    final Range range = focusedRange.asRange();
    final ColorPopup popup = new ColorPopup(button.getButton().hackGetWidget().getElement(), allowNone);
    popup.show(new OnColorChooseListener() {
      @Override
      public void onColorChoose(String color) {
        EditorAnnotationUtil.
            setAnnotationOverRange(editor.getDocument(), editor.getCaretAnnotations(),
                StyleAnnotationHandler.key(suffix), color, range.getStart(), range.getEnd());
        popup.hide();
        editor.focus(false);
      }

      @Override
      public void onNoneColorChoose() {
        EditorAnnotationUtil.
        clearAnnotationsOverRange(editor.getDocument(), editor.getCaretAnnotations(),
            new String[] {StyleAnnotationHandler.key(suffix)}, range.getStart(), range.getEnd());
        popup.hide();
        editor.focus(false);
      }});
  }
View Full Code Here

  private void maybeSetOrUpdateTitle() {
    if (blipUi != null && editor != null) {
      CMutableDocument document = editor.getDocument();
      ConversationBlip editBlip = views.getBlip(blipUi);
      if (editBlip.isRoot() && !TitleHelper.hasExplicitTitle(document)) {
        Range titleRange = TitleHelper.findImplicitTitle(document);
        TitleHelper.setImplicitTitle(document, titleRange.getStart(), titleRange.getEnd());
      }
    }
  }
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.