Package com.intellij.openapi.editor

Examples of com.intellij.openapi.editor.SelectionModel


    }

    public String preprocessOnPaste(Project project, PsiFile file, Editor editor, String text, RawText rawText) {
        Document document = editor.getDocument();
        PsiDocumentManager.getInstance(project).commitDocument(document);
        SelectionModel selectionModel = editor.getSelectionModel();

        // pastes in block selection mode (column mode) are not handled by a CopyPasteProcessor
        int selectionStart = selectionModel.getSelectionStart();
        int selectionEnd = selectionModel.getSelectionEnd();
        IElementType tokenType = findLiteralTokenType(file, selectionStart, selectionEnd);

        if (tokenType == HaskellTokenTypes.STRING) {
            if (rawText != null && rawText.rawText != null)
                return rawText.rawText; // Copied from the string literal. Copy as is.
View Full Code Here


    }

    public void loadFromEditor(@NotNull FileEditorStateLevel level, @NotNull TextEditor textEditor) {
        Editor editor = textEditor.getEditor();
        Project project = editor.getProject();
        SelectionModel selectionModel = editor.getSelectionModel();
        LogicalPosition logicalPosition = editor.getCaretModel().getLogicalPosition();

        line = logicalPosition.line;
        column = logicalPosition.column;

        if(FileEditorStateLevel.FULL == level) {
            selectionStart = selectionModel.getSelectionStart();
            selectionEnd = selectionModel.getSelectionEnd();

/*            if(project != null){
                PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
                CodeFoldingState foldingState = CodeFoldingManager.getInstance(project).saveFoldingState(editor);
                setFoldingState(foldingState);
View Full Code Here

    }

    public void applyToEditor(@NotNull TextEditor textEditor) {
        final Editor editor = textEditor.getEditor();
        final Project project = editor.getProject();
        SelectionModel selectionModel = editor.getSelectionModel();

        LogicalPosition logicalPosition = new LogicalPosition(line, column);
        editor.getCaretModel().moveToLogicalPosition(logicalPosition);
        selectionModel.removeSelection();
        editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
        if (verticalScrollProportion != -1F)
            EditorUtil.setVerticalScrollProportion(editor, verticalScrollProportion);
        Document document = editor.getDocument();
        if (selectionStart == selectionEnd) {
            selectionModel.removeSelection();
        } else {
            int selectionStart = Math.min(this.selectionStart, document.getTextLength());
            int selectionEnd = Math.min(this.selectionEnd, document.getTextLength());
            selectionModel.setSelection(selectionStart, selectionEnd);
        }
        ((EditorEx) editor).stopOptimizedScrolling();
        editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);

View Full Code Here

        Document document = DocumentUtil.getDocument(file);
        if (document != null && document.isWritable()) {
            Editor[] editors = EditorFactory.getInstance().getEditors(document);
            if (editors.length == 1) {
                Editor editor = editors[0];
                SelectionModel selectionModel = editor.getSelectionModel();
                int selectionStart = selectionModel.getSelectionStart();
                int selectionEnd = selectionModel.getSelectionEnd();
                format(document, file, selectionStart, selectionEnd);
            }
        }
    }
View Full Code Here

  @Nullable
  public static SelectionModel getSelectionModel(@NotNull final DataContext dataContext) {
    //final Editor editor = (Editor) dataContext.getData(DataConstants.EDITOR);
    final Editor editor = DataKeys.EDITOR.getData(dataContext);
    if (editor != null) {
      final SelectionModel model = editor.getSelectionModel();
      if (model.hasSelection()) {
        return model;
      }
    }
    return null;
  }
View Full Code Here

      }
    }

    PsiElement element1 = null;
    PsiElement element2 = null;
    final SelectionModel selectionModel = editor.getSelectionModel();
    if (selectionModel.hasSelection()) {
      element1 = file.findElementAt(selectionModel.getSelectionStart());
      element2 = file.findElementAt(selectionModel.getSelectionEnd() - 1);
      if (element1 instanceof PsiWhiteSpace) {
        int startOffset = element1.getTextRange().getEndOffset();
        element1 = file.findElementAt(startOffset);
      }
      if (element2 instanceof PsiWhiteSpace) {
View Full Code Here

                //Column mode not supported
                if (editor.isColumnMode()) {
                    return;
                }

                final SelectionModel selectionModel = editor.getSelectionModel();
                if (selectionModel.hasSelection()) {

                    final String selectedText = selectionModel.getSelectedText();


                    String[] textParts = selectedText.split("\n");
                    Collection<String> result = new ArrayList<String>();

                    for (String textPart : textParts) {
                        if (StringUtils.isNotBlank(textPart)) {
                            result.add(textPart);
                        }
                    }


                    String[] res = result.toArray(new String[result.size()]);

                    final String s = StringUtils.join(res, '\n');
                    editor.getDocument().replaceString(selectionModel.getSelectionStart(),
                            selectionModel.getSelectionEnd(), s);
                }

            }
        });
    }
View Full Code Here

        final int line = caretModel.getLogicalPosition().line;
        final int column = caretModel.getLogicalPosition().column;
        long offset = caretModel.getOffset();

        final SelectionModel selectionModel = editor.getSelectionModel();
        boolean hasSelection = selectionModel.hasSelection();
        if (hasSelection == false) {
          selectionModel.selectLineAtCaret();
        }
        final String selectedText = selectionModel.getSelectedText();

        if (selectedText != null) {
          String[] textParts = StringUtil.splitPreserveAllTokens(selectedText,
              DuplicatUtils.SIMPLE_NUMBER_REGEX);
          for (int i = 0; i < textParts.length; i++) {
            textParts[i] = DuplicatUtils.simpleDec(textParts[i]);
          }

          final String s = StringUtils.join(textParts);
          editor.getDocument().insertString(selectionModel.getSelectionStart(), s);

          if (hasSelection) {
            long selectionStart = selectionModel.getSelectionStart();
            long selectionEnd = selectionModel.getSelectionEnd();
            long length = s.length();
            caretModel.moveToOffset((int) (offset));
            selectionModel.setSelection((int) (selectionStart -length), (int) (selectionEnd -length));
            editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
          } else {
            selectionModel.removeSelection();
            caretModel.moveToLogicalPosition(new LogicalPosition(line, column));
          }
        }
      }
    });
View Full Code Here

  protected SwapCharactersAction() {
    super(null);

    this.setupHandler(new EditorWriteActionHandler() {
      public void executeWriteAction(Editor editor, DataContext dataContext) {
        final SelectionModel selectionModel = editor.getSelectionModel();


        int selectionStart = selectionModel.getSelectionStart();
        int selectionEnd = selectionModel.getSelectionEnd();

        final Document document = editor.getDocument();
        final int textLength = document.getTextLength();
        if (selectionModel.hasBlockSelection()) {
          int[] blockStarts = selectionModel.getBlockSelectionStarts();
          int[] blockEnds = selectionModel.getBlockSelectionEnds();
          int plusOffset = 0;

          for (int i = 0; i < blockStarts.length; i++) {
            int blockStart = blockStarts[i];
            int blockEnd = blockEnds[i];
            if (blockStart == blockEnd) {
              blockStart--;
              blockEnd++;
            }
            if (blockStart<0 || blockEnd > textLength) {
              continue;
            }
            String selectedText = document.getText(TextRange.create(blockStart, blockEnd));
            String newTextPart = transform(selectedText);

            document.replaceString(blockStart + plusOffset, blockEnd + plusOffset, newTextPart);

            int realOldTextLength = blockEnd - blockStart;
            plusOffset += newTextPart.length() - realOldTextLength;
          }
        } else {
          String selectedText = selectionModel.getSelectedText();
          if (selectedText == null) {
            selectionStart = selectionStart - 1;
            selectionEnd = selectionEnd + 1;
            if (selectionStart<0 || selectionEnd > textLength) {
              return;
View Full Code Here

                //Column mode not supported
                if (editor.isColumnMode()) {
                    return;
                }

                final SelectionModel selectionModel = editor.getSelectionModel();
                if (selectionModel.hasSelection()) {

                    String grepos = Messages.showInputDialog(editor.getProject(), "Grep text", "Grep", null);
                    if (StringUtil.isEmptyOrSpaces(grepos)) {
                        return;
                    }
                    final String selectedText = selectionModel.getSelectedText();


                    String[] textParts = selectedText.split("\n");
                    Collection<String> result = new ArrayList<String>();

                    for (String textPart : textParts) {
                        if (textPart.contains(grepos)) {
                            result.add(textPart);
                        }
                    }


                    String[] res = result.toArray(new String[result.size()]);

                    final String s = StringUtils.join(res, '\n');
                    editor.getDocument().replaceString(selectionModel.getSelectionStart(),
                            selectionModel.getSelectionEnd(), s);
                } else {
                    Messages.showInfoMessage(editor.getProject(), "Please select text, before using grep",
                            "Grep");
                }
View Full Code Here

TOP

Related Classes of com.intellij.openapi.editor.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.