Package com.intellij.openapi.editor

Examples of com.intellij.openapi.editor.Document


                                @NotNull final Editor editor,
                                @NotNull final Ref<Integer> caretOffset,
                                @NotNull final Ref<Integer> caretAdvance,
                                @NotNull final DataContext dataContext,
                                final EditorActionHandler originalHandler) {
    Document document = editor.getDocument();
    CharSequence text = document.getCharsSequence();
    int offset = caretOffset.get();
    if (!CodeInsightSettings.getInstance().SMART_INDENT_ON_ENTER) {
      return Result.Continue;
    }
View Full Code Here


        return new Runnable() {
          @Override
          public void run() {
            try {
              final PsiDocumentManager manager = PsiDocumentManager.getInstance(getProject());
              final Document document = manager.getDocument(file);

              assert document != null;

              for (int lineNum = 0; lineNum < document.getLineCount(); lineNum++) {
                CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(getProject());
                int offset = document.getLineStartOffset(lineNum);
                @SuppressWarnings("deprecation") // if this breaks at some point, we should
                  // refactor to invoke AutoIndentLinesAction
                  // instead of doing the indent directly
                  boolean lineToBeIndented = codeStyleManager.isLineToBeIndented(file, offset);
                if (lineToBeIndented) {
View Full Code Here

    if (actual.startsWith("\n")) {
      actual = actual.substring(1);
    }

    // Strip trailing spaces
    final Document doc = EditorFactory.getInstance().createDocument(actual);
    CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
      @Override
      public void run() {
        ApplicationManager.getApplication().runWriteAction(new Runnable() {
          @Override
          public void run() {
            ((DocumentImpl)doc).stripTrailingSpaces();
          }
        });
      }
    }, "formatting", null);

    return doc.getText();
  }
View Full Code Here

            return;
        }

        // Process input and add to history
        Editor editor = console.getCurrentEditor();
        Document document = editor.getDocument();
        final CaretModel caretModel = editor.getCaretModel();
        final int offset = caretModel.getOffset();
        String text = document.getText();

        if (!"".equals(text.substring(offset).trim())) {
            String before = text.substring(0, offset);
            String after = text.substring(offset);
            final int indent = 0;
View Full Code Here

    }

    private void execute(LanguageConsoleImpl languageConsole,
                         ConsoleHistoryModel consoleHistoryModel) {
        // Process input and add to history
        Document document = languageConsole.getCurrentEditor().getDocument();
        String text = document.getText();
        TextRange range = new TextRange(0, document.getTextLength());

        languageConsole.getCurrentEditor().getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset());
        languageConsole.addCurrentToHistory(range, false, preserveMarkup);
        languageConsole.setInputText("");
        if (!StringUtil.isEmptyOrSpaces(text)) {
View Full Code Here

    public static LineCol fromOffset(PsiFile psiFile, int offset) {
        VirtualFile file = psiFile.getVirtualFile();
        if (file == null)
            return null;
        FileDocumentManager fdm = FileDocumentManager.getInstance();
        Document doc = fdm.getCachedDocument(file);
        if (doc == null)
            return null;
        int line = doc.getLineNumber(offset);
        int col = offset - doc.getLineStartOffset(line);
        return new LineCol(line + 1, col + 1);
    }
View Full Code Here

        }
        return isLiteral ? Unescaper.unescape(text) : null;
    }

    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();
View Full Code Here

                }
            }

            private void removeImport(LineColRange range) {
                PsiDocumentManager manager = PsiDocumentManager.getInstance(psiFile.getProject());
                Document document = manager.getDocument(psiFile);
                if (document == null)
                    return;
                manager.commitDocument(document);
                TextRange textRange = range.getRange(psiFile);
                int start = textRange.getStartOffset();
                int end = textRange.getEndOffset();
                int line = document.getLineNumber(end);
                int lineStart = document.getLineStartOffset(line);
                int lineEnd = document.getLineEndOffset(line);
                String functionName = document.getText(textRange);
                String importLine = document.getText().substring(lineStart, lineEnd);
                int rightWhites = getWhites(Pattern.compile(".*" + functionName + "([ ]*,[ ]*).*"), importLine);
                if (rightWhites == 0) {
                    start -= getWhites(Pattern.compile(".*(,[ ]*)" + functionName + ".*"), importLine);
                } else {
                    end += rightWhites;
                }
                boolean isEndOfLine = document.getLineEndOffset(line) == end;
                int endOffset = isEndOfLine ? end + document.getLineSeparatorLength(line) : end;
                document.replaceString(start, endOffset, "");
            }
        };
    }
View Full Code Here

                        buffer.append("\n");
                        buffer.append(postfix);
                    }
                    buffer.append("\n");
                }
                Document document = DocumentUtil.getDocument(ddlFile);
                document.setText(buffer.toString());
            }
        }
    }
View Full Code Here

public class DocumentUtil {


    public static void touchDocument(final Editor editor) {
        final Document document = editor.getDocument();

        // restart highlighting
        final PsiFile file = DocumentUtil.getFile(editor);
        if (file instanceof DBLanguageFile) {
            DBLanguageFile dbLanguageFile = (DBLanguageFile) file;
            DBLanguage dbLanguage = dbLanguageFile.getDBLanguage();
            if (dbLanguage != null) {
                ConnectionHandler connectionHandler = dbLanguageFile.getActiveConnection();
                DBLanguageSyntaxHighlighter syntaxHighlighter = getSyntaxHighlighter(dbLanguage, connectionHandler);

                EditorHighlighter editorHighlighter = HighlighterFactory.createHighlighter(syntaxHighlighter, editor.getColorsScheme());
                ((EditorEx) editor).setHighlighter(editorHighlighter);
            }
        }

        new CommandWriteActionRunner(editor.getProject()) {
            public void run() {
                // touch the editor to trigger parsing

                String text = document.getText();
                BlockSupport.getInstance(file.getProject()).reparseRange(file, 0, text.length(), text);
                refreshEditorAnnotations(file);
            }
        }.start();
View Full Code Here

TOP

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