Package com.google.collide.shared.document

Examples of com.google.collide.shared.document.Line


    if (beginLine == endLine) {
      return beginLine.getText().substring(beginColumn, endColumn + 1);
    }

    StringBuilder s = new StringBuilder(beginLine.getText().substring(beginColumn));
    Line line = beginLine.getNextLine();
    while (line != null && line != endLine) {
      s.append(line.getText());
      line = line.getNextLine();
    }
    if (line == null) {
      throw new IndexOutOfBoundsException();
    }
    s.append(endLine.getText().substring(0, endColumn + 1));
View Full Code Here


  public void deleteCharacter(boolean afterCursor) {
    if (tryDeleteSelection()) {
      return;
    }

    Line cursorLine = selection.getCursorLine();
    int cursorLineNumber = selection.getCursorLineNumber();
    int deleteColumn = !afterCursor ? selection.getCursorColumn() - 1 : selection.getCursorColumn();
    if (cursorLine.hasColumn(deleteColumn)) {
      getEditorDocumentMutator().deleteText(cursorLine, cursorLineNumber, deleteColumn, 1);
    } else if (deleteColumn < 0 && cursorLine.getPreviousLine() != null) {
      // Join the lines
      Line previousLine = cursorLine.getPreviousLine();
      getEditorDocumentMutator().deleteText(previousLine, cursorLineNumber - 1,
          previousLine.getText().length() - 1, 1);
    }
  }
View Full Code Here

  public void deleteWord(boolean afterCursor) {
    if (tryDeleteSelection()) {
      return;
    }

    Line cursorLine = selection.getCursorLine();
    int cursorColumn = selection.getCursorColumn();

    boolean mergeWithPreviousLine = cursorColumn == 0 && !afterCursor;
    boolean mergeWithNextLine = cursorColumn == cursorLine.length() - 1 && afterCursor;
    if (mergeWithPreviousLine || mergeWithNextLine) {
      // Re-use delete character logic
      deleteCharacter(afterCursor);
      return;
    }

    int otherColumn =
        afterCursor ? TextUtils.findNextWord(cursorLine.getText(), cursorColumn, true) : TextUtils
            .findPreviousWord(cursorLine.getText(), cursorColumn, false);
    editorDocumentMutator.deleteText(cursorLine, Math.min(otherColumn, cursorColumn),
        Math.abs(otherColumn - cursorColumn));
  }
View Full Code Here

    Preconditions.checkArgument(
        begin.getLineNumber() <= end.getLineNumber(), "begin line below end line");

    // TODO: Fix same-line text replacement.
    LineInfo topLineInfo = begin.getLineInfo();
    Line topLine = topLineInfo.line();
    Line bottomLine = end.getLine();

    /*
     * At the very end of the document, the text being inserted will have a
     * trailing "\n" that needs to be deleted to avoid an empty line at the
     * end.
     */
    boolean deleteEndingNewline = !bottomLine.getText().endsWith("\n");
    if (!text.endsWith("\n")) {
      text = text + "\n";
    }
    // Delete all of the existing text, minus the last newline.
    int deleteCount =
        LineUtils.getTextCount(topLine, 0, bottomLine, bottomLine.getText().length() -
          (deleteEndingNewline ? 0 : 1));

    documentMutator.insertText(topLine, topLineInfo.number(), 0, text, false);
    Position endOfInsertion =
        PositionUtils.getPosition(topLine, topLineInfo.number(), 0, text.length() - 1);
View Full Code Here

   * @param type the @{link AnchorType} of the anchor, or null to capture any type.
   * @param next true if the search is forwards, false for backwards
   * @return the adjacent anchor, or null if no such anchor is found
   */
  private Anchor getAdjacentAnchor(Anchor anchor, AnchorType type, boolean next) {
    Line currentLine = anchor.getLine();
    AnchorList list = getAnchors(currentLine);

    // Special case for the same line
    int insertionIndex = list.findInsertionIndex(anchor);
    int lowerBound = next ? 0 : 1;
    int upperBound = next ? list.size() - 2 : list.size() - 1;
    if (insertionIndex >= lowerBound && insertionIndex <= upperBound) {
      Anchor anchorInList = list.get(insertionIndex);
      if (anchor == anchorInList) {
        // We found the anchor in the list, and we have a neighbor to return
        Anchor candidateAnchor;
        if (next) {
          candidateAnchor = list.get(insertionIndex + 1);
        } else {
          candidateAnchor = list.get(insertionIndex - 1);
        }
        // Enforce the type
        if (type != null && !candidateAnchor.getType().equals(type)) {
          return getAdjacentAnchor(candidateAnchor, type, next);
        } else {
          return candidateAnchor;
        }
      }
      // Otherwise, the anchor must be on another line
    }

    currentLine = next ? currentLine.getNextLine() : currentLine.getPreviousLine();
    while (currentLine != null) {
      list = getAnchorsOrNull(currentLine);
      if (list != null && list.size() > 0) {
        Anchor candidateAnchor;
        if (next) {
          candidateAnchor = list.get(0);
        } else {
          candidateAnchor = list.get(list.size() - 1);
        }
        // Enforce the type
        if (type != null && !candidateAnchor.getType().equals(type)) {
          return getAdjacentAnchor(candidateAnchor, type, next);
        } else {
          return candidateAnchor;
        }
      }
      currentLine = next ? currentLine.getNextLine() : currentLine.getPreviousLine();
    }

    return null;
  }
View Full Code Here

        && anchor.getColumn() == column) {
      return;
    }

    // Remove the anchor
    Line oldLine = anchor.getLine();
    AnchorList oldAnchors = getAnchorsOrNull(oldLine);
    if (oldAnchors == null) {
      throw new IllegalStateException("List of line's anchors should not be null\nLine anchors:\n"
          + dumpAnchors(lineAnchors));
    }
View Full Code Here

  public void testInsertionSpaceBeforeTab() {
    Document doc = Document.createFromString("\t123");
    LineDimensionsCalculator.createWithCustomProvider(new TestMeasurementProvider(0))
        .handleDocumentChange(doc);
    Line line = doc.getFirstLine();
    assertFalse(LineDimensionsUtils.needsOffset(line));
    doc.insertText(line, 0, 0, " ");
    assertTrue(LineDimensionsUtils.needsOffset(line));
  }
View Full Code Here

  public void testInsertionTabBeforeTab() {
    Document doc = Document.createFromString("\t123");
    LineDimensionsCalculator.createWithCustomProvider(new TestMeasurementProvider(0))
        .handleDocumentChange(doc);
    Line line = doc.getFirstLine();
    assertFalse(LineDimensionsUtils.needsOffset(line));
    doc.insertText(line, 0, 0, "\t");
    assertFalse(LineDimensionsUtils.needsOffset(line));
  }
View Full Code Here

  public void testInsertionSpaceAfter() {
    Document doc = Document.createFromString("\t123");
    LineDimensionsCalculator.createWithCustomProvider(new TestMeasurementProvider(0))
        .handleDocumentChange(doc);
    Line line = doc.getFirstLine();
    assertFalse(LineDimensionsUtils.needsOffset(line));
    doc.insertText(line, 0, 1, " ");
    assertFalse(LineDimensionsUtils.needsOffset(line));
  }
View Full Code Here

  public void testInsertionTabAfterTab() {
    Document doc = Document.createFromString("\t123");
    LineDimensionsCalculator.createWithCustomProvider(new TestMeasurementProvider(0))
        .handleDocumentChange(doc);
    Line line = doc.getFirstLine();
    assertFalse(LineDimensionsUtils.needsOffset(line));
    doc.insertText(line, 0, 1, "\t");
    assertFalse(LineDimensionsUtils.needsOffset(line));
  }
View Full Code Here

TOP

Related Classes of com.google.collide.shared.document.Line

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.