Package com.google.collide.client.editor.selection

Examples of com.google.collide.client.editor.selection.SelectionModel


        "color: black;\n",
        "fake: ;\n",
        "}\n"
    });
    helper.setup(new PathUtil("test.css"), text, 1, 3, false);
    SelectionModel selection = helper.editor.getSelection();

    AutocompleteProposals completions = cssAutocompleter.findAutocompletions(selection, CTRL_SPACE);
    assertEquals(1, completions.size());
    AutocompleteResult commonResult = cssAutocompleter.computeAutocompletionResult(
        completions.select(0));
    assertTrue("result type", commonResult instanceof DefaultAutocompleteResult);
    DefaultAutocompleteResult result = (DefaultAutocompleteResult) commonResult;
    assertEquals(8, result.getJumpLength());
    assertEquals("cursor: ;", result.getAutocompletionText());

    CssCompletionQuery query = cssAutocompleter.updateOrCreateQuery(
        null, selection.getCursorPosition());
    JsoArray<String> completedProperties = query.getCompletedProperties();
    assertEquals(2, completedProperties.size());
    assertEquals("color", completedProperties.get(0));
    assertEquals("fake", completedProperties.get(1));
  }
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

    editor.getEditorDocumentMutator().insertText(line, lineNumber, lastCursorColumn, "\n");
  }

  private void splitLine(Editor editor) {
    // TODO: Add language specific logic (i.e. string splitting).
    SelectionModel selection = editor.getSelection();
    Position[] selectionRange = selection.getSelectionRange(false);
    Position cursor = selectionRange[0];

    editor.getEditorDocumentMutator().insertText(cursor.getLine(), cursor.getLineNumber(),
        cursor.getColumn(), "\n", true);
    selection.setCursorPosition(cursor.getLineInfo(), cursor.getColumn());
  }
View Full Code Here

  private void saveSelection() {
    if (fileEditSessionKey == null) {
      return;
    }

    SelectionModel selectionModel = editor.getSelection();
    Buffer buffer = editor.getBuffer();

    int cursorLineNumber = selectionModel.getCursorLineNumber();
    int cursorScrollTopOffset = buffer.calculateLineTop(cursorLineNumber) - buffer.getScrollTop();

    selections.put(fileEditSessionKey, new Selection(selectionModel.getBaseLineNumber(),
        selectionModel.getBaseColumn(), cursorLineNumber, selectionModel.getCursorColumn(),
        cursorScrollTopOffset));
  }
View Full Code Here

    return popupAction;
  }

  @Override
  public void apply(Editor editor) {
    SelectionModel selection = editor.getSelection();
    Position[] selectionRange = selection.getSelectionRange(false);
    boolean selectionChanged = false;

    // 1) New beginning of selection based on suffix-matching and
    //    backspaceCount
    Position selectionStart = selectionRange[0];
    int selectionStartColumn = selectionStart.getColumn();
    String textBefore = selectionStart.getLine().getText().substring(0, selectionStartColumn);
    if (!textBefore.endsWith(preContentSuffix)) {
      Log.warn(getClass(),
          "expected suffix [" + preContentSuffix + "] do not match [" + textBefore + "]");
      return;
    }
    int matchCount = preContentSuffix.length();

    int leftOffset = backspaceCount + matchCount;
    if (leftOffset > 0) {
      selectionStart = getPosition(selectionStart, -leftOffset);
      selectionChanged = true;
    }

    // 2) Calculate end of selection
    Position selectionEnd = selectionRange[1];
    if (deleteCount > 0) {
      selectionEnd = getPosition(selectionEnd, deleteCount);
      selectionChanged = true;
    }

    // 3) Set selection it was changed.
    if (selectionChanged) {
      selection.setSelection(selectionStart.getLineInfo(), selectionStart.getColumn(),
          selectionEnd.getLineInfo(), selectionEnd.getColumn());
    }

    // 4) Replace selection
    EditorDocumentMutator mutator = editor.getEditorDocumentMutator();
    if (selection.hasSelection() || autocompletionText.length() > 0) {
      mutator.insertText(selectionStart.getLine(), selectionStart.getLineNumber(),
          selectionStart.getColumn(), autocompletionText);
    }

    // 5) Move cursor / set final selection
    selectionEnd = getPosition(selectionStart, jumpLength);
    if (selectionCount == 0) {
      selection.setCursorPosition(selectionEnd.getLineInfo(), selectionEnd.getColumn());
    } else {
      selectionStart = getPosition(selectionStart, jumpLength - selectionCount);
      selection.setSelection(selectionStart.getLineInfo(), selectionStart.getColumn(),
          selectionEnd.getLineInfo(), selectionEnd.getColumn());
    }
  }
View Full Code Here

  }

  private void goToDefinitionAtCurrentCaretPosition() {
    // TODO: Check here that our code model is fresh enough.
    // int caretOffset = getCaretOffset(editor.getWidget().getElement());
    SelectionModel selection = editor.getSelection();
    LineInfo lineInfo = new LineInfo(selection.getCursorLine(), selection.getCursorLineNumber());
    NavigableReference reference =
        referenceStore.findReference(lineInfo, selection.getCursorColumn(), true);
    navigateReference(reference);
  }
View Full Code Here

TOP

Related Classes of com.google.collide.client.editor.selection.SelectionModel

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.