Package com.google.collide.shared.document

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


   * @param lines Number of lines to include in viewport
   */
  public static ViewportModel createMockViewport(Document document, int lines) {
    ViewportModel mockViewport = EasyMock.createMock(ViewportModel.class);

    Line curLine = document.getFirstLine();
    expect(mockViewport.getTopLine()).andReturn(curLine).anyTimes();
    expect(mockViewport.getTopLineNumber()).andReturn(0).anyTimes();
    expect(mockViewport.getTopLineInfo()).andAnswer(lineInfoFactory(curLine, 0)).anyTimes();
    for (int i = 0; i < lines - 1 && curLine.getNextLine() != null; i++) {
      curLine = curLine.getNextLine();
    }
    expect(mockViewport.getBottomLine()).andReturn(curLine).anyTimes();
    expect(mockViewport.getBottomLineNumber()).andReturn(lines - 1).anyTimes();
    expect(mockViewport.getBottomLineInfo()).andAnswer(
        lineInfoFactory(curLine, lines - 1)).anyTimes();
View Full Code Here


  /**
   * Retrieves the line info of a given line
   */
  public static LineInfo gotoLineInfo(Document document, int line) {
    Line curLine = document.getFirstLine();
    for (int i = 0; curLine != null && i < line; i++) {
      curLine = curLine.getNextLine();
    }
    return new LineInfo(curLine, line);
  }
View Full Code Here

    State parserState = loadParserStateForBeginningOfLine(line);
    if (parserState == null) {
      return false;
    }

    Line previousLine = line.getPreviousLine();

    for (int numLinesProcessed = 0; line != null && numLinesProcessed < numLinesToProcess;) {
      State stateToSave = parserState;
      if (line.getText().length() > LINE_LENGTH_LIMIT) {
        // Save the initial state instead of state at the end of line.
        stateToSave = parserState.copy(codeMirrorParser);
      }

      JsonArray<Token> tokens;
      try {
        tokens = parseLine(parserState, line.getText());
      } catch (ParserException e) {
        Log.error(getClass(), "Could not parse line:", line, e);
        return false;
      }

      // Restore the initial line state if it was preserved.
      parserState = stateToSave;
      saveEndOfLineParserState(line, parserState);
      tokensRecipient.onTokensParsed(line, lineNumber, tokens);

      previousLine = line;
      line = line.getNextLine();
      numLinesProcessed++;
      if (lineNumber != -1) {
        lineNumber++;
      }
    }

    if (anchorToUpdate != null) {
      if (lineNumber == -1) {
        throw new IllegalArgumentException("lineNumber cannot be -1 if anchorToUpdate is given");
      }

      if (line != null) {
        line.getDocument().getAnchorManager()
            .moveAnchor(anchorToUpdate, line, lineNumber, AnchorManager.IGNORE_COLUMN);
      } else {
        previousLine.getDocument().getAnchorManager()
            .moveAnchor(anchorToUpdate, previousLine, lineNumber - 1, AnchorManager.IGNORE_COLUMN);
      }
    }

    return line != null;
View Full Code Here

   *                     if {@code null} then nothing is appended.
   * @return {@code null} if it is currently impossible to parse.
   */
  <T extends State> ParseResult<T> getParserState(
      Position position, @Nullable String appendedText) {
    Line line = position.getLine();
    T parserState = loadParserStateForBeginningOfLine(line);
    if (parserState == null) {
      return null;
    }
    String lineText = line.getText().substring(0, position.getColumn());
    if (appendedText != null) {
     lineText = lineText + appendedText;
    }

    JsonArray<Token> tokens;
View Full Code Here

       * For insertion, the second line through the second-to-last line can't
       * have existed in the document, so no point in marking them dirty.
       */
      TextChange textChange = textChanges.get(i);

      Line line = textChange.getLine();
      Line lastLine = textChange.getLastLine();

      if (dirtyLines.indexOf(line) == -1) {
        dirtyLines.add(line);
      }

View Full Code Here

      relevantContentChangedLineNumber = lineNumber;
    }

    if (!added) {
      for (int i = 0, n = lines.size(); i < n; i++) {
        Line curLine = lines.get(i);
        if (ViewportRenderer.isRendered(curLine)) {
          viewportRemovedLines.add(curLine);
        }
      }
    }
View Full Code Here

      if (toInsert == 0) {
        return null;
      }

      final Line line = LineUtils.getLine(textChange.getLine(), 1);
      final int lineNumber = textChange.getLineNumber() + 1;
      return new Runnable() {
        @Override
        public void run() {
          String addend = StringUtils.getSpaces(toInsert);
View Full Code Here

        //               documentParser.getElectricCharacters.
        return null;
      }

      // TODO: Ask parser to reparse changed line.
      final Line line = LineUtils.getLine(textChange.getLine(), 1);

      // Special case: pressing ENTER in the middle of whitespaces line should
      // not fix indentation (use case: press ENTER on empty line).
      Line prevLine = textChange.getLine();
      if (WHITESPACES.test(prevLine.getText()) && WHITESPACES.test(line.getText())) {
        return null;
      }

      final int lineNumber = textChange.getLineNumber() + 1;
      final int indentation = documentParser.getIndentation(line);
View Full Code Here

  }

  private void startNewLine(Editor editor) {
    SelectionModel selection = editor.getSelection();
    selection.deselect();
    Line line = selection.getCursorLine();
    int lineNumber = selection.getCursorLineNumber();
    int lastCursorColumn = LineUtils.getLastCursorColumn(line);
    selection.setCursorPosition(new LineInfo(line, lineNumber), lastCursorColumn);
    editor.getEditorDocumentMutator().insertText(line, lineNumber, lastCursorColumn, "\n");
  }
View Full Code Here

    });
    return createdSpacer;
  }

  public void removeSpacer(final Spacer spacer) {
    final Line spacerLine = spacer.getLine();
    final int spacerLineNumber = spacer.getLineNumber();
    if (coordinateMap.removeSpacer(spacer)) {
      updateBufferHeightAndMaybeScrollTop(convertLineNumberToY(spacerLineNumber),
          -spacer.getHeight());
      spacerListenerManager.dispatch(new Dispatcher<Buffer.SpacerListener>() {
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.