Package com.google.collide.shared.document.anchor

Examples of com.google.collide.shared.document.anchor.AnchorManager


  private Document() {
    firstLine = lastLine = Line.create(this, "");
    firstLine.setAttached(true);

    anchorManager = new AnchorManager();

    documentMutator = new DocumentMutatorImpl(this);

    lineListenerManager = ListenerManager.create();
View Full Code Here


    this.viewport = viewport;
    this.animationController = new AnimationController(editorView);
  }

  private void placeOldViewportAnchors() {
    AnchorManager anchorManager = document.getAnchorManager();
    if (viewportOldTopAnchor == null) {
      viewportOldTopAnchor =
          anchorManager.createAnchor(OLD_VIEWPORT_ANCHOR_TYPE, viewport.getTopLine(),
              viewport.getTopLineNumber(), AnchorManager.IGNORE_COLUMN);
      viewportOldTopAnchor.setRemovalStrategy(RemovalStrategy.SHIFT);

      viewportOldBottomAnchor =
          anchorManager.createAnchor(OLD_VIEWPORT_ANCHOR_TYPE, viewport.getBottomLine(),
              viewport.getBottomLineNumber(), AnchorManager.IGNORE_COLUMN);
      viewportOldBottomAnchor.setRemovalStrategy(RemovalStrategy.SHIFT);

    } else {
      anchorManager.moveAnchor(viewportOldTopAnchor, viewport.getTopLine(),
          viewport.getTopLineNumber(), AnchorManager.IGNORE_COLUMN);
      anchorManager.moveAnchor(viewportOldBottomAnchor, viewport.getBottomLine(),
          viewport.getBottomLineNumber(), AnchorManager.IGNORE_COLUMN);
    }
  }
View Full Code Here

   * Using the current rendering state, calculate the length and style for the
   * next diff chunk.
   */
  private void calculateNextChunk() {
    // Get the previous anchor for this line
    AnchorManager anchorManager = document.getAnchorManager();

    if (prevAnchor == null) {
      Anchor startSearchAnchor = document.getAnchorManager().createAnchor(
          START_SEARCH_ANCHOR_TYPE, line, AnchorManager.IGNORE_LINE_NUMBER, 1);
      prevAnchor = document.getAnchorManager().getPreviousAnchor(startSearchAnchor, anchorType);
      document.getAnchorManager().removeAnchor(startSearchAnchor);
      if (prevAnchor == null) {
        return;
      }
    } else {
      // We have hit an anchor on this line already, get the next one.
      prevAnchor = anchorManager.getNextAnchor(prevAnchor, anchorType);
    }

    Anchor nextAnchor = anchorManager.getNextAnchor(prevAnchor, anchorType);
    if (nextAnchor != null && nextAnchor.getLine() == line) {
      nextChunkLength = nextAnchor.getColumn() - linePosition;
    } else {
      nextChunkLength = line.getText().length() - linePosition;
    }
View Full Code Here

    AnchorType bottomType = AnchorType.create(EditorTests.class, "bottom");
    AnchorType topType = AnchorType.create(EditorTests.class, "top");

    Document doc = Document.createFromString("qwerty\nasdfgh\nzxcvbn\n");
    LineFinder lineFinder = doc.getLineFinder();
    AnchorManager anchorManager = doc.getAnchorManager();
    LineInfo lineInfo = lineFinder.findLine(1);

    Editor editor = Editor.create(new MockAppContext());
    editor.setDocument(doc);

    Anchor topAnchor = anchorManager.createAnchor(topType, lineInfo.line(), lineInfo.number(),
        AnchorManager.IGNORE_COLUMN);
    topAnchor.setRemovalStrategy(Anchor.RemovalStrategy.SHIFT);
    topAnchor.setInsertionPlacementStrategy(InsertionPlacementStrategy.EARLIER);

    Anchor bottomAnchor = anchorManager.createAnchor(bottomType, lineInfo.line(), lineInfo.number(),
        AnchorManager.IGNORE_COLUMN);
    bottomAnchor.setRemovalStrategy(Anchor.RemovalStrategy.SHIFT);
    bottomAnchor.setInsertionPlacementStrategy(InsertionPlacementStrategy.LATER);

    SelectionModel selection = editor.getSelection();
View Full Code Here

    }

    JsonArray<Anchor> anchors = JsonCollections.createArray();
    collectAttachedAnchors(anchors, root);

    AnchorManager anchorManager = document.getAnchorManager();
    for (int i = 0, l = anchors.size(); i < l; i++) {
      anchorManager.removeAnchor(anchors.get(i));
    }

    root = null;
    document = null;
  }
View Full Code Here

  @Override
  public void onCleanup(JsonArray<OutlineNode> nodes) {
    final int l = nodes.size();
    if (l > 0) {
      AnchorManager anchorManager =
          nodes.get(0).getAnchor().getLine().getDocument().getAnchorManager();
      for (int i = 0; i < l; i++) {
        Anchor anchor = nodes.get(i).getAnchor();
        if (anchor.isAttached()) {
          anchorManager.removeAnchor(anchor);
        }
      }
    }
  }
View Full Code Here

   */
  protected void bindNodes(Document target) {
    // At least root node is listed
    Preconditions.checkState(!allNodes.isEmpty());

    AnchorManager anchorManager = target.getAnchorManager();

    LineFinder lineFinder = target.getLineFinder();
    LineInfo cursor = lineFinder.findLine(0);
    int lastLineNumber = target.getLastLineNumber();

View Full Code Here

    lineTokens.add(new Token(CodeMirror2.HTML, TokenType.WHITESPACE, " "));

    prepareAutocompleter();

    Document document = helper.editor.getDocument();
    AnchorManager anchorManager = document.getAnchorManager();
    Line line = document.getFirstLine();
    HtmlAutocompleter htmlAutocompleter = helper.autocompleter.htmlAutocompleter;

    // Delete the anchor that was set by prepareAutocompleter().
    JsonArray<Anchor> anchors =
        AnchorManager.getAnchorsByTypeOrNull(line, HtmlAutocompleter.MODE_ANCHOR_TYPE);
    assertEquals(0, anchors.size());

    assertEquals(CodeMirror2.HTML, htmlAutocompleter.getModeForColumn(line, 0));
    assertEquals(CodeMirror2.HTML, htmlAutocompleter.getModeForColumn(line, 1));
    assertEquals(CodeMirror2.HTML, htmlAutocompleter.getModeForColumn(line, 2));
    assertEquals(CodeMirror2.HTML, htmlAutocompleter.getModeForColumn(line, 3));

    Anchor anchor = anchorManager.createAnchor(HtmlAutocompleter.MODE_ANCHOR_TYPE, line,
        AnchorManager.IGNORE_LINE_NUMBER, 2);
    anchor.setValue("m1");
    assertEquals(CodeMirror2.HTML, htmlAutocompleter.getModeForColumn(line, 0));
    assertEquals(CodeMirror2.HTML, htmlAutocompleter.getModeForColumn(line, 1));
    assertEquals(CodeMirror2.HTML, htmlAutocompleter.getModeForColumn(line, 2));
    assertEquals("m1", htmlAutocompleter.getModeForColumn(line, 3));
    assertEquals("m1", htmlAutocompleter.getModeForColumn(line, 4));
    assertEquals("m1", htmlAutocompleter.getModeForColumn(line, 5));
    assertEquals("m1", htmlAutocompleter.getModeForColumn(line, 6));
    assertEquals("m1", htmlAutocompleter.getModeForColumn(line, 10));

    anchor = anchorManager.createAnchor(HtmlAutocompleter.MODE_ANCHOR_TYPE, line,
        AnchorManager.IGNORE_LINE_NUMBER, 1);
    anchor.setValue("m0");
    assertEquals(CodeMirror2.HTML, htmlAutocompleter.getModeForColumn(line, 0));
    assertEquals(CodeMirror2.HTML, htmlAutocompleter.getModeForColumn(line, 1));
    assertEquals("m0", htmlAutocompleter.getModeForColumn(line, 2));
    assertEquals("m1", htmlAutocompleter.getModeForColumn(line, 3));
    assertEquals("m1", htmlAutocompleter.getModeForColumn(line, 4));
    assertEquals("m1", htmlAutocompleter.getModeForColumn(line, 5));
    assertEquals("m1", htmlAutocompleter.getModeForColumn(line, 6));
    assertEquals("m1", htmlAutocompleter.getModeForColumn(line, 10));

    anchor = anchorManager.createAnchor(HtmlAutocompleter.MODE_ANCHOR_TYPE, line,
        AnchorManager.IGNORE_LINE_NUMBER, 5);
    anchor.setValue("m2");
    assertEquals(CodeMirror2.HTML, htmlAutocompleter.getModeForColumn(line, 0));
    assertEquals(CodeMirror2.HTML, htmlAutocompleter.getModeForColumn(line, 1));
    assertEquals("m0", htmlAutocompleter.getModeForColumn(line, 2));
    assertEquals("m1", htmlAutocompleter.getModeForColumn(line, 3));
    assertEquals("m1", htmlAutocompleter.getModeForColumn(line, 4));
    assertEquals("m1", htmlAutocompleter.getModeForColumn(line, 5));
    assertEquals("m2", htmlAutocompleter.getModeForColumn(line, 6));
    assertEquals("m2", htmlAutocompleter.getModeForColumn(line, 10));

    anchor = anchorManager.createAnchor(HtmlAutocompleter.MODE_ANCHOR_TYPE, line,
        AnchorManager.IGNORE_LINE_NUMBER, 4);
    anchor.setValue("m3");
    assertEquals(CodeMirror2.HTML, htmlAutocompleter.getModeForColumn(line, 0));
    assertEquals(CodeMirror2.HTML, htmlAutocompleter.getModeForColumn(line, 1));
    assertEquals("m0", htmlAutocompleter.getModeForColumn(line, 2));
View Full Code Here

      @Nonnull JsonArray<Pair<Integer, String>> modes) {
    Preconditions.checkState(currentLine instanceof Line);
    // TODO: pull AnchorManager.getAnchorsByTypeOrNull to
    // TaggableLine interface (for decoupling).
    Line line = (Line) currentLine;
    AnchorManager anchorManager = line.getDocument().getAnchorManager();
    Preconditions.checkNotNull(anchorManager);
    JsonArray<Anchor> oldAnchors =
        AnchorManager.getAnchorsByTypeOrNull(line, MODE_ANCHOR_TYPE);
    if (oldAnchors != null) {
      for (Anchor anchor : oldAnchors.asIterable()) {
        anchorManager.removeAnchor(anchor);
      }
    }
    for (Pair<Integer, String> pair : modes.asIterable()) {
      Anchor anchor = anchorManager.createAnchor(MODE_ANCHOR_TYPE, line,
          AnchorManager.IGNORE_LINE_NUMBER, pair.first);
      anchor.setRemovalStrategy(Anchor.RemovalStrategy.SHIFT);
      anchor.setValue(pair.second);
    }
  }
View Full Code Here

TOP

Related Classes of com.google.collide.shared.document.anchor.AnchorManager

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.