Package com.google.collide.shared.document

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


     */
    commandMode.addShortcut(new EventShortcut(ModifierKeys.NONE, 'O') {
      @Override
      public boolean event(InputScheme scheme, SignalEvent event) {
        SelectionModel selectionModel = getInputController().getEditor().getSelection();
        Document document = getInputController().getEditor().getDocument();
        Line cursorLine = selectionModel.getCursorLine();
        int cursorLineNumber = selectionModel.getCursorLineNumber();
        document.insertText(cursorLine, 0, "\n");
        selectionModel.setCursorPosition(new LineInfo(cursorLine, cursorLineNumber), 0);
        switchMode(Modes.INSERT);
        return true;
      }
    });

    /*
     * o - Insert line below, enter insert mode.
     */
    commandMode.addShortcut(new EventShortcut(ModifierKeys.NONE, 'o') {
      @Override
      public boolean event(InputScheme scheme, SignalEvent event) {
        SelectionModel selectionModel = getInputController().getEditor().getSelection();
        Document document = getInputController().getEditor().getDocument();
        Line cursorLine = selectionModel.getCursorLine();
        int cursorLineNumber = selectionModel.getCursorLineNumber();
        document.insertText(cursorLine, LineUtils.getLastCursorColumn(cursorLine), "\n");
        selectionModel.setCursorPosition(new LineInfo(cursorLine.getNextLine(),
            cursorLineNumber + 1), 0);
        switchMode(Modes.INSERT);
        return true;
      }
    });

    /*
     * : - Switch to colon capture mode for commands.
     */
    commandMode.addShortcut(new EventShortcut(ModifierKeys.NONE, ':') {
      @Override
      public boolean event(InputScheme scheme, SignalEvent event) {
        switchMode(Modes.COMMAND_CAPTURE);
        return true;
      }
    });

    /*
     * "/" - Switch to search mode.
     */
    commandMode.addShortcut(new EventShortcut(ModifierKeys.NONE, '/') {
      @Override
      public boolean event(InputScheme scheme, SignalEvent event) {
        switchMode(Modes.SEARCH_CAPTURE);
        return true;
      }
    });

    commandMode.addShortcut(new EventShortcut(ModifierKeys.NONE, '*') {
      @Override
      public boolean event(InputScheme scheme, SignalEvent event) {
        SelectionModel selectionModel = getInputController().getEditor().getSelection();
        String word =
            TextUtils.getWordAtColumn(selectionModel.getCursorLine().getText(),
                selectionModel.getCursorColumn());
        if (word == null) {
          return true;
        }
        switchMode(Modes.SEARCH_CAPTURE);
        searchTerm.append(word);
        doPartialSearch();
        drawSearchTerm();
        return true;
      }
    });

    /*
     * Movement
     */
    /*
     * ^,0 - Move to first character in line.
     */
    commandMode.addShortcut(new EventShortcut(ModifierKeys.NONE, '^') {
      @Override
      public boolean event(InputScheme scheme, SignalEvent event) {
        SelectionModel selectionModel = getInputController().getEditor().getSelection();
        LineInfo cursorLineInfo =
            new LineInfo(selectionModel.getCursorLine(), selectionModel.getCursorLineNumber());
        selectionModel.setCursorPosition(cursorLineInfo, 0);
        return true;
      }
    });
    commandMode.addShortcut(new EventShortcut(ModifierKeys.NONE, '0') {
      @Override
      public boolean event(InputScheme scheme, SignalEvent event) {
        if (tryAddNumericPrefix('0')) {
          return true;
        }
        SelectionModel selectionModel = getInputController().getEditor().getSelection();
        LineInfo cursorLineInfo =
            new LineInfo(selectionModel.getCursorLine(), selectionModel.getCursorLineNumber());
        selectionModel.setCursorPosition(cursorLineInfo, 0);
        return true;
      }
    });

    /*
     * $ - Move to end of line.
     */
    commandMode.addShortcut(new EventShortcut(ModifierKeys.NONE, '$') {
      @Override
      public boolean event(InputScheme scheme, SignalEvent event) {
        SelectionModel selectionModel = getInputController().getEditor().getSelection();
        Line cursorLine = selectionModel.getCursorLine();
        LineInfo cursorLineInfo = new LineInfo(cursorLine, selectionModel.getCursorLineNumber());
        selectionModel.setCursorPosition(cursorLineInfo, LineUtils.getLastCursorColumn(cursorLine));
        return true;
      }
    });

    /*
     * w - move the cursor to the first character of the next word.
     */
    commandMode.addShortcut(new EventShortcut(ModifierKeys.NONE, 'w') {
      @Override
      public boolean event(InputScheme scheme, SignalEvent event) {
        SelectionModel selectionModel = getInputController().getSelection();
        LineInfo cursorLineInfo =
            new LineInfo(selectionModel.getCursorLine(), selectionModel.getCursorLineNumber());
        String text = selectionModel.getCursorLine().getText();
        int column = selectionModel.getCursorColumn();
        column = TextUtils.moveByWord(text, column, true, false);
        if (column == -1) {
          Line cursorLine = cursorLineInfo.line().getNextLine();
          if (cursorLine != null) {
            cursorLineInfo = new LineInfo(cursorLine, cursorLineInfo.number() + 1);
            column = 0;
          } else {
            column = LineUtils.getLastCursorColumn(cursorLine); // at last character
                                                          // in document
          }
        }

        selectionModel.setCursorPosition(cursorLineInfo, column);
        return true;
      }
    });

    /*
     * b - move the cursor to the first character of the previous word.
     */
    commandMode.addShortcut(new EventShortcut(ModifierKeys.NONE, 'b') {
      @Override
      public boolean event(InputScheme scheme, SignalEvent event) {
        SelectionModel selectionModel = getInputController().getSelection();
        LineInfo cursorLineInfo =
            new LineInfo(selectionModel.getCursorLine(), selectionModel.getCursorLineNumber());
        String text = selectionModel.getCursorLine().getText();
        int column = selectionModel.getCursorColumn();
        column = TextUtils.moveByWord(text, column, false, false);
        if (column == -1) {
          Line cursorLine = cursorLineInfo.line().getPreviousLine();
          if (cursorLine != null) {
            cursorLineInfo = new LineInfo(cursorLine, cursorLineInfo.number() - 1);
            column = LineUtils.getLastCursorColumn(cursorLine);
          } else {
            column = 0; // at first character in document
          }
        }

        selectionModel.setCursorPosition(cursorLineInfo, column);
        return true;
      }
    });

    /*
     * e - move the cursor to the last character of the next word.
     */
    commandMode.addShortcut(new EventShortcut(ModifierKeys.NONE, 'e') {
      @Override
      public boolean event(InputScheme scheme, SignalEvent event) {
        SelectionModel selectionModel = getInputController().getSelection();
        LineInfo cursorLineInfo =
            new LineInfo(selectionModel.getCursorLine(), selectionModel.getCursorLineNumber());
        String text = selectionModel.getCursorLine().getText();
        int column = selectionModel.getCursorColumn();
        column = TextUtils.moveByWord(text, column, true, true);
        if (column == -1) {
          Line cursorLine = cursorLineInfo.line().getNextLine();
          if (cursorLine != null) {
            cursorLineInfo = new LineInfo(cursorLine, cursorLineInfo.number() + 1);
            column = 0;
          } else {
            // at the last character in the document
            column = LineUtils.getLastCursorColumn(cursorLine);
          }
        }

        selectionModel.setCursorPosition(cursorLineInfo, column);
        return true;
      }
    });

    /*
     * % - jump to the next matching {}, [] or () character if the cursor is
     * over one of the two.
     */
    commandMode.addShortcut(new EventShortcut(ModifierKeys.NONE, '%') {
      @Override
      public boolean event(InputScheme scheme, SignalEvent event) {
        final SelectionModel selectionModel = getInputController().getSelection();
        Document document = getInputController().getEditor().getDocument();
        LineInfo cursorLineInfo =
            new LineInfo(selectionModel.getCursorLine(), selectionModel.getCursorLineNumber());
        String text = selectionModel.getCursorLine().getText();
        final char cursorChar = text.charAt(selectionModel.getCursorColumn());
        final char searchChar;
        final boolean searchingForward = OPENING_GROUPS.indexOf(cursorChar) >= 0;
        final Position searchingTo;
        if (searchingForward) {
          searchChar = CLOSING_GROUPS.charAt(OPENING_GROUPS.indexOf(cursorChar));
          searchingTo =
              new Position(new LineInfo(document.getLastLine(), document.getLastLineNumber()),
                  document.getLastLine().length());
        } else if (CLOSING_GROUPS.indexOf(cursorChar) >= 0) {
          searchChar = OPENING_GROUPS.charAt(CLOSING_GROUPS.indexOf(cursorChar));
          searchingTo = new Position(new LineInfo(document.getFirstLine(), 0), 0);
        } else {
          return true; // not on a valid starting character
        }


View Full Code Here


    }
  }

  private void selectNextNLines(int numLines) {
    SelectionModel selectionModel = getInputController().getEditor().getSelection();
    Document document = getInputController().getEditor().getDocument();
    Line cursorLine = selectionModel.getCursorLine();
    int cursorLineNumber = selectionModel.getCursorLineNumber();
    LineInfo cursorLineInfo = new LineInfo(cursorLine, cursorLineNumber);
    LineInfo endLineInfo;
    if (cursorLineNumber + numLines > document.getLastLineNumber()) {
      endLineInfo = new LineInfo(document.getLastLine(), document.getLastLineNumber());
    } else {
      endLineInfo =
          cursorLine.getDocument().getLineFinder()
              .findLine(cursorLineInfo, cursorLineNumber + numLines);
    }
View Full Code Here

  /**
   * Jump to lineNumber (1-based). If requested number is invalid, either go to
   * the first line or the last line, depending upon defaultToFirstLine.
   */
  private void moveCursorToLine(int lineNumber, boolean defaultToFirstLine) {
    Document document = getInputController().getEditor().getDocument();
    SelectionModel selectionModel = getInputController().getEditor().getSelection();
    LineInfo targetLineInfo;
    if (lineNumber > document.getLastLineNumber() + 1 || lineNumber <= 0) {
      if (defaultToFirstLine) {
        targetLineInfo = new LineInfo(document.getFirstLine(), 0);
      } else {
        targetLineInfo = new LineInfo(document.getLastLine(), document.getLastLineNumber());
      }
    } else {
      Line cursorLine = selectionModel.getCursorLine();
      int cursorLineNumber = selectionModel.getCursorLineNumber();
      LineInfo cursorLineInfo = new LineInfo(cursorLine, cursorLineNumber);
View Full Code Here

  public void removeLineRenderer(LineRenderer lineRenderer) {
    renderer.removeLineRenderer(lineRenderer);
  }

  public void setDocument(final Document document) {
    final Document oldDocument = this.document;

    if (oldDocument != null) {
      // Teardown the objects depending on the old document
      renderer.teardown();
      viewport.teardown();
View Full Code Here

   
    Resources mockResources = createMockResource();
    SearchMatchRenderer renderer = new SearchMatchRenderer(mockResources, mockSearchModel);
   
    // Now ask it about each line in our document and check to see if its right
    Document doc = SearchTestsUtil.createDocument();
    LineInfo lineInfo = doc.getFirstLineInfo();
    for (int i = 0; i < 6; i++) {
      assertFalse(renderer.resetToBeginningOfLine(lineInfo.line(), lineInfo.number()));
      lineInfo.moveToNext();
    }
   
View Full Code Here

    checkCut(text, 2, 0, text);
    // Assert: still alive.
  }

  private void checkCut(String text, int line, int column, String expected) {
    Document document = Document.createFromString(text);
    final Editor editor = Editor.create(new MockAppContext());
    editor.setDocument(document);

    LineInfo lineInfo = document.getLineFinder().findLine(line);
    editor.getSelection().setSelection(lineInfo, column, lineInfo, column);
    editor.getInput().processSignalEvent(TestCutPasteEvent.create(null));
    assertEquals(expected, document.asText());
  }
View Full Code Here

  private void checkExplicit(String message, String text, int tailOffset,
      SignalEventEssence trigger, @Nullable DefaultAutocompleteResult expected) {
    MockAutocompleterEnvironment helper = new MockAutocompleterEnvironment();

    Document document = Document.createFromString(text);
    int column = LineUtils.getLastCursorColumn(document.getFirstLine()) - tailOffset;
    helper.setup(new PathUtil("foo.js"), document, 0, column, true);

    ExplicitAction action = helper.autocompleter.jsAutocompleter.getExplicitAction(
        helper.editor.getSelection(), trigger, false);
    AutocompleteResult commonResult = action.getExplicitAutocompletion();
View Full Code Here

* Tests for {@link LineDimensionsUtils}.
*/
public class LineDimensionsUtilsTests extends TestCase {

  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

    doc.insertText(line, 0, 0, " ");
    assertTrue(LineDimensionsUtils.needsOffset(line));
  }

  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

    doc.insertText(line, 0, 0, "\t");
    assertFalse(LineDimensionsUtils.needsOffset(line));
  }

  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

TOP

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

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.