Search in sources :

Example 86 with DocumentEx

use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.

the class PythonConsoleView method doAddPromptToHistory.

protected final void doAddPromptToHistory(boolean isMainPrompt) {
    flushDeferredText();
    EditorEx viewer = getHistoryViewer();
    DocumentEx document = viewer.getDocument();
    RangeHighlighter highlighter = getHistoryViewer().getMarkupModel().addRangeHighlighter(document.getTextLength(), document.getTextLength(), 0, null, HighlighterTargetArea.EXACT_RANGE);
    final String prompt;
    if (isMainPrompt) {
        prompt = myPromptView.getMainPrompt();
        print(prompt + " ", myPromptView.getPromptAttributes());
    } else {
        prompt = myPromptView.getIndentPrompt();
        //todo should really be myPromptView.getPromptAttributes() output type
        //but in that case flushing doesn't get handled correctly. Take a look at it later
        print(prompt + " ", ConsoleViewContentType.USER_INPUT);
    }
    highlighter.putUserData(PyConsoleCopyHandler.PROMPT_LENGTH_MARKER, prompt.length() + 1);
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) EditorEx(com.intellij.openapi.editor.ex.EditorEx)

Example 87 with DocumentEx

use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.

the class PythonConsoleView method executeInConsole.

public void executeInConsole(final String code) {
    TransactionGuard.submitTransaction(this, () -> {
        final String codeToExecute = code.endsWith("\n") || myExecuteActionHandler.checkSingleLine(code) ? code : code + "\n";
        DocumentEx document = getConsoleEditor().getDocument();
        String oldText = document.getText();
        ApplicationManager.getApplication().runWriteAction(() -> {
            setInputText(codeToExecute);
            PsiDocumentManager.getInstance(getProject()).commitDocument(document);
            PsiFile psiFile = PsiDocumentManager.getInstance(getProject()).getPsiFile(document);
            if (psiFile != null) {
                CommandProcessor.getInstance().runUndoTransparentAction(() -> CodeStyleManager.getInstance(getProject()).adjustLineIndent(psiFile, new TextRange(0, psiFile.getTextLength())));
            }
        });
        int oldOffset = getConsoleEditor().getCaretModel().getOffset();
        getConsoleEditor().getCaretModel().moveToOffset(document.getTextLength());
        myExecuteActionHandler.runExecuteAction(this);
        if (!StringUtil.isEmpty(oldText)) {
            ApplicationManager.getApplication().runWriteAction(() -> setInputText(oldText));
            getConsoleEditor().getCaretModel().moveToOffset(oldOffset);
        }
    });
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) PsiFile(com.intellij.psi.PsiFile) TextRange(com.intellij.openapi.util.TextRange)

Aggregations

DocumentEx (com.intellij.openapi.editor.ex.DocumentEx)87 Document (com.intellij.openapi.editor.Document)12 NotNull (org.jetbrains.annotations.NotNull)8 RangeMarkerEx (com.intellij.openapi.editor.ex.RangeMarkerEx)7 Project (com.intellij.openapi.project.Project)7 TextRange (com.intellij.openapi.util.TextRange)7 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)7 PsiFile (com.intellij.psi.PsiFile)6 Nullable (org.jetbrains.annotations.Nullable)5 EditorEx (com.intellij.openapi.editor.ex.EditorEx)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 MockVirtualFile (com.intellij.mock.MockVirtualFile)3 FoldRegion (com.intellij.openapi.editor.FoldRegion)3 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)3 DocumentWindow (com.intellij.injected.editor.DocumentWindow)2 DocumentBulkUpdateListener (com.intellij.openapi.editor.ex.DocumentBulkUpdateListener)2 DocumentImpl (com.intellij.openapi.editor.impl.DocumentImpl)2 DocumentMarkupModel (com.intellij.openapi.editor.impl.DocumentMarkupModel)2 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)2 FileDocumentManagerAdapter (com.intellij.openapi.fileEditor.FileDocumentManagerAdapter)2