Package com.google.collide.shared.document

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


    int lineLength = text.length();
    if (text.endsWith("\n")) {
      lineLength--;
    }
    int column = Math.min(initialColumn, lineLength);
    selection.setCursorPosition(new LineInfo(line, lineNumber), column);
  }
View Full Code Here


  }

  private class AsyncSearchTask implements IncrementalScheduler.Task {
    @Override
    public boolean run(int workAmount) {
      LineInfo lineInfo = searchTaskAnchor.getLineInfo();

      for (; lineInfo.line() != stopLineAnchor.getLine() && workAmount > 0; workAmount--) {
        if (!executor.onSearchLine(lineInfo.line(), lineInfo.number(), false)) {
          dispatchSearchDone();
          return false;
        }

        if (!lineInfo.moveTo(searchDirectionHelper.isGoingDown())) {
          if (shouldWrapDocument) {
            lineInfo = searchDirectionHelper.getWrapDocumentLine();
          } else {
            dispatchSearchDone();
            return false;
          }
        }
      }

      if (lineInfo.line() == stopLineAnchor.getLine()) {
        dispatchSearchDone();
        return false;
      }

      document.getAnchorManager().moveAnchor(
          searchTaskAnchor, lineInfo.line(), lineInfo.number(), AnchorManager.IGNORE_COLUMN);
      dispatchSearchProgress();
      return true;
    }
View Full Code Here

   * Performs specified movement action.
   */
  public void move(MoveAction action, boolean isShiftHeld) {
    boolean shouldUpdatePreferredColumn = true;
    int column = cursorAnchor.getColumn();
    LineInfo lineInfo = cursorAnchor.getLineInfo();
    String lineText = lineInfo.line().getText();

    switch (action) {
      case LEFT:
        column = TextUtils.findPreviousNonMarkNorOtherCharacter(lineText, column);
        break;

      case RIGHT:
        column = TextUtils.findNonMarkNorOtherCharacter(lineText, column);
        break;

      case WORD_LEFT:
        column = TextUtils.findPreviousWord(lineText, column, false);
        /**
         * {@link TextUtils#findNextWord} can return line length indicating it's
         * at the end of a word on the line. If this line ends in a* {@code \n}
         * that will cause us to move to the next line when we check
         * {@link LineUtils#getLastCursorColumn} which isn't what we want. So
         * fix it now in case the lines ends in {@code \n}.
         */
        if (column == lineInfo.line().length()) {
          column = rubberbandColumn(lineInfo.line(), column);
        }
        break;

      case WORD_RIGHT:
        column = TextUtils.findNextWord(lineText, column, true);
        /**
         * {@link TextUtils#findNextWord} can return line length indicating it's
         * at the end of a word on the line. If this line ends in a* {@code \n}
         * that will cause us to move to the next line when we check
         * {@link LineUtils#getLastCursorColumn} which isn't what we want. So
         * fix it now in case the lines ends in {@code \n}.
         */
        if (column == lineInfo.line().length()) {
          column = rubberbandColumn(lineInfo.line(), column);
        }
        break;

      case UP:
        column = preferredCursorColumn;
        if (lineInfo.line() == document.getFirstLine() && (isShiftHeld || UserAgent.isMac())) {
          /*
           * Pressing up on the first line should:
           * - On Mac, always go to first column, or
           * - On all platforms, shift+up should select to first column
           */
          column = 0;
        } else {
          lineInfo.moveToPrevious();
        }

        column = rubberbandColumn(lineInfo.line(), column);
        shouldUpdatePreferredColumn = false;
        break;

      case DOWN:
        column = preferredCursorColumn;
        if (lineInfo.line() == document.getLastLine() && (isShiftHeld || UserAgent.isMac())) {
          // Consistent with up-arrowing on first line
          column = LineUtils.getLastCursorColumn(lineInfo.line());
        } else {
          lineInfo.moveToNext();
        }

        column = rubberbandColumn(lineInfo.line(), column);
        shouldUpdatePreferredColumn = false;
        break;

      case PAGE_UP:
        for (int i = buffer.getFlooredHeightInLines(); i > 0; i--) {
          lineInfo.moveToPrevious();
        }
        column = rubberbandColumn(lineInfo.line(), preferredCursorColumn);
        shouldUpdatePreferredColumn = false;
        break;

      case PAGE_DOWN:
        for (int i = buffer.getFlooredHeightInLines(); i > 0; i--) {
          lineInfo.moveToNext();
        }
        column = rubberbandColumn(lineInfo.line(), preferredCursorColumn);
        shouldUpdatePreferredColumn = false;
        break;

      case LINE_START:
        int firstNonWhitespaceColumn = TextUtils.countWhitespacesAtTheBeginningOfLine(
            lineInfo.line().getText());
        column = (column != firstNonWhitespaceColumn) ? firstNonWhitespaceColumn : 0;
        break;

      case LINE_END:
        column = LineUtils.getLastCursorColumn(lineInfo.line());
        break;

      case TEXT_START:
        lineInfo = new LineInfo(document.getFirstLine(), 0);
        column = 0;
        break;

      case TEXT_END:
        lineInfo = new LineInfo(document.getLastLine(), document.getLineCount() - 1);
        column = LineUtils.getLastCursorColumn(lineInfo.line());
        break;
    }

    if (column < 0) {
      if (lineInfo.moveToPrevious()) {
        column = getLastCursorColumn(lineInfo.line());
      } else {
        column = 0;
      }
    } else if (column > getLastCursorColumn(lineInfo.line())) {
      if (lineInfo.moveToNext()) {
        column = LineUtils.getFirstCursorColumn(lineInfo.line());
      } else {
        column = rubberbandColumn(lineInfo.line(), column);
      }
    }

    moveCursor(lineInfo, column, shouldUpdatePreferredColumn, isShiftHeld,
        getSelectionRangeForCallback());
View Full Code Here

     * frontend are also applied in the same rendering pass as a deletion.
     */
    int createOffset = removedLines.size() * buffer.getEditorLineHeight();
    if (beginLineNumber <= viewport.getBottomLineNumber()) {
      // Only fill or update lines if the content change affects the viewport
      LineInfo beginLine =
          viewport.getDocument().getLineFinder().findLine(viewport.getBottom(), beginLineNumber);
      animationController.onBeforeAnimationStarted();
      fillOrUpdateLines(beginLine.line(), beginLine.number(), viewport.getBottomLine(),
          viewport.getBottomLineNumber(), createOffset);
    }
  }
View Full Code Here

    if (changedEdges.contains(ViewportModel.Edge.TOP)) {
      /*
       * Collaborator added/removed lines above us, update the viewport lines
       * since their tops may have changed
       */
      LineInfo top = viewport.getTop();
      LineInfo bottom = viewport.getBottom();
      fillOrUpdateLines(top.line(), top.number(), bottom.line(), bottom.number(), 0);
    }
  }
View Full Code Here

 
  /**
   * Renders changes to the viewport positioning.
   */
  void renderViewportShift(boolean forceRerender) {
    LineInfo oldTop = viewportOldTopAnchor != null ? viewportOldTopAnchor.getLineInfo() : null;
    LineInfo oldBottom =
        viewportOldBottomAnchor != null ? viewportOldBottomAnchor.getLineInfo() : null;

    LineInfo top = viewport.getTop();
    LineInfo bottom = viewport.getBottom();

    if (oldTop == null || oldBottom == null || bottom.number() < oldTop.number()
        || top.number() > oldBottom.number() || forceRerender) {
      /*
       * The viewport does not overlap with its old position, GC old lines and
       * render all of the new ones (or we are forced to rerender everything)
       */
      if (oldTop != null && oldBottom != null) {
        garbageCollectLines(oldTop.line(), oldTop.number(), oldBottom.line(), oldBottom.number());
      }

      fillOrUpdateLines(top.line(), top.number(), bottom.line(), bottom.number(), 0);

    } else {
      // There is some overlap, so be more efficient with our update
      if (oldTop.number() < top.number()) {
        // The viewport moved down, need to GC the offscreen lines
        garbageCollectLines(top.line().getPreviousLine(), top.number() - 1, oldTop.line(),
            oldTop.number());
      } else if (oldTop.number() > top.number()) {
        // The viewport moved up, need to fill with lines
        fillOrUpdateLines(top.line(), top.number(), oldTop.line().getPreviousLine(),
            oldTop.number() - 1, 0);
      }

      if (oldBottom.number() < bottom.number()) {
        // The viewport moved down, need to fill with lines
        fillOrUpdateLines(oldBottom.line().getNextLine(), oldBottom.number() + 1, bottom.line(),
            bottom.number(), 0);
      } else if (oldBottom.number() > bottom.number()) {
        // The viewport moved up, need to GC the offscreen lines
        garbageCollectLines(bottom.line().getNextLine(), bottom.number() + 1, oldBottom.line(),
            oldBottom.number());
      }
    }
  }
View Full Code Here

        column -= numCharsToTraverse;
        numCharsToTraverse = 0;
      }
    }

    return new Position(new LineInfo(line, lineNumber), column);
  }
View Full Code Here

        column += numCharsToTraverse;
        numCharsToTraverse = 0;
      }
    }

    return new Position(new LineInfo(line, lineNumber), column);
  }
View Full Code Here

    editorUndoManager.redo();
  }

  public void scrollTo(int lineNumber, int column) {
    if (document != null) {
      LineInfo lineInfo = document.getLineFinder().findLine(lineNumber);
      /*
       * TODO: the cursor will be the last line in the viewport,
       * fix this
       */
      SelectionModel selectionModel = getSelection();
View Full Code Here

  }

  @Override
  public void onMouseClick(Buffer buffer, int clickCount, int x, int y, boolean isShiftHeld) {
    int lineNumber = buffer.convertYToLineNumber(y, true);
    LineInfo newLineInfo =
        buffer.getDocument().getLineFinder().findLine(cursorAnchor.getLineInfo(), lineNumber);
    int newColumn = buffer.convertXToRoundedVisibleColumn(x, newLineInfo.line());
    // Allow the user to keep clicking to iterate through selection modes
    clickCount = (clickCount - 1) % 3 + 1;

    selectionGranularity = SelectionGranularity.forClickCount(clickCount);
View Full Code Here

TOP

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

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.