Search in sources :

Example 11 with DocumentEx

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

the class PsiToDocumentSynchronizer method doCommitTransaction.

private static void doCommitTransaction(@NotNull Document document, @NotNull DocumentChangeTransaction documentChangeTransaction) {
    DocumentEx ex = (DocumentEx) document;
    ex.suppressGuardedExceptions();
    try {
        boolean isReadOnly = !document.isWritable();
        ex.setReadOnly(false);
        for (Map.Entry<TextRange, CharSequence> entry : documentChangeTransaction.myAffectedFragments.descendingMap().entrySet()) {
            ex.replaceString(entry.getKey().getStartOffset(), entry.getKey().getEndOffset(), entry.getValue());
        }
        ex.setReadOnly(isReadOnly);
    } finally {
        ex.unSuppressGuardedExceptions();
    }
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) ImmutableCharSequence(com.intellij.util.text.ImmutableCharSequence) TextRange(com.intellij.openapi.util.TextRange)

Example 12 with DocumentEx

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

the class SelectInEditorManagerImpl method doSelect.

private void doSelect(final boolean toUseNormalSelection, @NotNull final Editor editor, final boolean toSelectLine, final TextRange textRange) {
    int startOffset = textRange.getStartOffset();
    int endOffset = textRange.getEndOffset();
    if (toUseNormalSelection) {
        DocumentEx doc = (DocumentEx) editor.getDocument();
        if (toSelectLine) {
            int lineNumber = doc.getLineNumber(startOffset);
            if (lineNumber >= 0 && lineNumber < doc.getLineCount()) {
                editor.getSelectionModel().setSelection(doc.getLineStartOffset(lineNumber), doc.getLineEndOffset(lineNumber) + doc.getLineSeparatorLength(lineNumber));
            }
        } else {
            editor.getSelectionModel().setSelection(startOffset, endOffset);
        }
        return;
    }
    TextAttributes selectionAttributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
    releaseAll();
    if (toSelectLine) {
        DocumentEx doc = (DocumentEx) editor.getDocument();
        int lineNumber = doc.getLineNumber(startOffset);
        if (lineNumber >= 0 && lineNumber < doc.getLineCount()) {
            mySegmentHighlighter = editor.getMarkupModel().addRangeHighlighter(doc.getLineStartOffset(lineNumber), doc.getLineEndOffset(lineNumber) + doc.getLineSeparatorLength(lineNumber), HighlighterLayer.LAST + 1, selectionAttributes, HighlighterTargetArea.EXACT_RANGE);
        }
    } else {
        mySegmentHighlighter = editor.getMarkupModel().addRangeHighlighter(startOffset, endOffset, HighlighterLayer.LAST + 1, selectionAttributes, HighlighterTargetArea.EXACT_RANGE);
    }
    myEditor = editor;
    myEditor.getContentComponent().addFocusListener(this);
    myEditor.getCaretModel().addCaretListener(this);
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes)

Example 13 with DocumentEx

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

the class UndoableGroup method getDocumentToSetBulkMode.

private static DocumentEx getDocumentToSetBulkMode(UndoableAction action) {
    // not allowed in bulk update.
    if (!(action instanceof EditorChangeAction))
        return null;
    //noinspection ConstantConditions
    DocumentReference newDocumentRef = action.getAffectedDocuments()[0];
    if (newDocumentRef == null)
        return null;
    VirtualFile file = newDocumentRef.getFile();
    if (file != null && !file.isValid())
        return null;
    return (DocumentEx) newDocumentRef.getDocument();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) DocumentReference(com.intellij.openapi.command.undo.DocumentReference)

Example 14 with DocumentEx

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

the class FileDocumentManagerImpl method getDocument.

@Override
@Nullable
public Document getDocument(@NotNull final VirtualFile file) {
    ApplicationManager.getApplication().assertReadAccessAllowed();
    DocumentEx document = (DocumentEx) getCachedDocument(file);
    if (document == null) {
        if (!file.isValid() || file.isDirectory() || isBinaryWithoutDecompiler(file))
            return null;
        boolean tooLarge = FileUtilRt.isTooLarge(file.getLength());
        if (file.getFileType().isBinary() && tooLarge)
            return null;
        final CharSequence text = tooLarge ? LoadTextUtil.loadText(file, getPreviewCharCount(file)) : LoadTextUtil.loadText(file);
        synchronized (lock) {
            document = (DocumentEx) getCachedDocument(file);
            // Double checking
            if (document != null)
                return document;
            document = (DocumentEx) createDocument(text, file);
            document.setModificationStamp(file.getModificationStamp());
            final FileType fileType = file.getFileType();
            document.setReadOnly(tooLarge || !file.isWritable() || fileType.isBinary());
            if (!(file instanceof LightVirtualFile || file.getFileSystem() instanceof NonPhysicalFileSystem)) {
                document.addDocumentListener(myPhysicalDocumentChangeTracker);
            }
            if (file instanceof LightVirtualFile) {
                registerDocument(document, file);
            } else {
                document.putUserData(FILE_KEY, file);
                cacheDocument(file, document);
            }
        }
        myMultiCaster.fileContentLoaded(file, document);
    }
    return document;
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) UnknownFileType(com.intellij.openapi.fileTypes.UnknownFileType) FileType(com.intellij.openapi.fileTypes.FileType) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with DocumentEx

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

the class EditorImplTest method testNoExceptionDuringBulkModeDocumentUpdate.

public void testNoExceptionDuringBulkModeDocumentUpdate() throws Exception {
    initText("something");
    DocumentEx document = (DocumentEx) myEditor.getDocument();
    runWriteCommand(() -> {
        DocumentUtil.executeInBulk(document, true, () -> {
            document.setText("something\telse");
        });
    });
    checkResultByText("something\telse");
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx)

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