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

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


   */
  public void testBackwardsTraversal() {
    AnchorList anchorList = anchorManager.getAnchors(doc.getLastLine());
    assertEquals(2, anchorList.size());

    Anchor anchor = docEnd;
    for (int i = anchors.size() - 1; i >= 0; i--) {
      assertSame(anchors.get(i), anchor);
      assertEquals(anchors.get(i).getType(), anchor.getType());
      anchor = anchorManager.getPreviousAnchor(anchor);
    }
  }
View Full Code Here


  /**
   * Currently, we rely on being able to push anchors past the end of the line.
   */
  public void testAnchorPastEnd() {
    Line line = doc.getFirstLine().getNextLine();
    Anchor anchor = anchorManager.createAnchor(ANCHOR_TYPE_1, line, IGNORE_LINE_NUMBER, 1);
    assertSame(anchorManager.getPreviousAnchor(anchor), firstEmptyLine);

    line = line.getNextLine();
    anchorManager.moveAnchor(anchor, line, IGNORE_LINE_NUMBER, 100);
    assertSame(anchorManager.getPreviousAnchor(anchor), theBeginning);
View Full Code Here

      if (a.getType().equals(ANCHOR_TYPE_1)) {
        type1Anchors.add(a);
      }
    }

    Anchor anchor = docStart;
    assertEquals(ANCHOR_TYPE_1, anchor.getType());
    for (Anchor a : type1Anchors) {
      assertSame(a, anchor);
      assertEquals(ANCHOR_TYPE_1, anchor.getType());
      anchor = anchorManager.getNextAnchor(anchor, ANCHOR_TYPE_1);
    }
    assertNull(anchor);
  }
View Full Code Here

    }
    assertNull(anchor);
  }

  public void testInsertionPlacementStrategyForLineAnchors() {
    Anchor a1 =
        createAnchorForPlacementStrategy(doc.getFirstLine(), true, IGNORE_COLUMN, EARLIER);
    Anchor a2 =
        createAnchorForPlacementStrategy(doc.getFirstLine(), true, IGNORE_COLUMN, LATER);
    assertAnchorLineNumbers(a1, 0, a2, 0);

    doc.insertText(doc.getFirstLine(), 0, "Newline\n");
    assertAnchorLineNumbers(a1, 0, a2, 1);
View Full Code Here

    doc.insertText(doc.getFirstLine(), 0, "Many\nnew\nlines\n!\n");
    assertAnchorLineNumbers(a1, 0, a2, 4);
  }

  public void testInsertionPlacementStrategyForColumnAnchors() {
    Anchor a1 = createAnchorForPlacementStrategy(doc.getFirstLine(), false, 0, EARLIER);
    Anchor a2 = createAnchorForPlacementStrategy(doc.getFirstLine(), false, 0, LATER);
    assertAnchorColumns(a1, 0, a2, 0);

    doc.insertText(doc.getFirstLine(), 0, "a");
    assertAnchorColumns(a1, 0, a2, 1);

    doc.deleteText(doc.getFirstLine(), 0, doc.getFirstLine().getText().length());
    assertAnchorColumns(a1, 0, a2, 0);

    doc.insertText(doc.getFirstLine(), 0, "more than a trivial insertion");
    assertAnchorColumns(a1, 0, a2, "more than a trivial insertion".length());

    doc.insertText(doc.getFirstLine(), 0, "\n");
    assertEquals(doc.getFirstLine(), a1.getLine());
    assertEquals(doc.getFirstLine().getNextLine(), a2.getLine());
    assertAnchorColumns(a1, 0, a2, "more than a trivial insertion".length());
  }
View Full Code Here

    assertEquals(doc.getFirstLine().getNextLine(), a2.getLine());
    assertAnchorColumns(a1, 0, a2, "more than a trivial insertion".length());
  }

  public void testInsertionPlacementStrategyForLineNumberAndColumnAnchors() {
    Anchor a1 = createAnchorForPlacementStrategy(doc.getFirstLine(), true, 1, EARLIER);
    Anchor a2 = createAnchorForPlacementStrategy(doc.getFirstLine(), true, 1, LATER);
    assertAnchorPositions(a1, 0, 1, a2, 0, 1);

    doc.insertText(doc.getFirstLine(), 0, "a");
    assertAnchorPositions(a1, 0, 2, a2, 0, 2);
View Full Code Here

    assertAnchorPositions(a1, 1, 0, a2, 5, "more than a trivial insertion".length());
  }

  private Anchor createAnchorForPlacementStrategy(Line line, boolean storeLineNumber, int column,
      InsertionPlacementStrategy insertionPlacementStrategy) {
    Anchor a =
        doc.getAnchorManager().createAnchor(ANCHOR_TYPE_1, doc.getFirstLine(),
            storeLineNumber ? doc.getLineFinder().findLine(line).number() : IGNORE_LINE_NUMBER,
            column);
    a.setInsertionPlacementStrategy(insertionPlacementStrategy);
    a.setRemovalStrategy(RemovalStrategy.SHIFT);
    return a;
  }
View Full Code Here

        columnAnchorOnLine0Newline.getColumn(), 1, "Hello worldFoo bar\n");
  }

  public void testViewportBottomShiftingOnSmallDocument() {
    Document doc = Document.createFromString("abc\n");
    Anchor bottomAnchor =
        doc.getAnchorManager().createAnchor(DOCUMENT_TEST_ANCHOR_TYPE, doc.getLastLine(), 1,
        IGNORE_COLUMN);
    deleteAndAssertEquals(doc.getFirstLine(), 3, 1, "abc");
    assertAnchorPosition(bottomAnchor, 0, false, IGNORE_COLUMN);
  }
View Full Code Here

  }

  public void testCursorAtEndOfOnlyLine() {
    Document doc = Document.createFromString("abc");
    // Column is the non-existent character after 'c'
    Anchor cursorAnchor =
        doc.getAnchorManager().createAnchor(DOCUMENT_TEST_ANCHOR_TYPE, doc.getFirstLine(), 0, 3);
    cursorAnchor.setRemovalStrategy(Anchor.RemovalStrategy.SHIFT);
    deleteAndAssertEquals(doc.getFirstLine(), 0, 3, "");
    assertAnchorPosition(cursorAnchor, 0, false, 0);
  }
View Full Code Here

   * "number of lines / 2".
   */
  private static List<Class<?>> setupForListenerCallbackOrdering(Document doc) {
    final List<Class<?>> callbackOrdering = Lists.newArrayList();
   
    Anchor shiftAnchor =
        doc.getAnchorManager().createAnchor(DOCUMENT_TEST_ANCHOR_TYPE,
            doc.getLineFinder().findLine(doc.getLineCount() / 2).line(), doc.getLineCount() / 2, 0);
    shiftAnchor.setRemovalStrategy(RemovalStrategy.SHIFT);
    shiftAnchor.getShiftListenerRegistrar().add(new ShiftListener() {
      @Override
      public void onAnchorShifted(Anchor anchor) {
        callbackOrdering.add(ShiftListener.class);
      }
    });

    Anchor removeAnchor =
      doc.getAnchorManager().createAnchor(DOCUMENT_TEST_ANCHOR_TYPE,
          doc.getLineFinder().findLine(doc.getLineCount() / 2).line(), doc.getLineCount() / 2, 0);
    removeAnchor.getRemoveListenerRegistrar().add(new RemoveListener() {
      @Override
      public void onAnchorRemoved(Anchor anchor) {
        callbackOrdering.add(RemoveListener.class);
      }
    });
View Full Code Here

TOP

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

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.