Search in sources :

Example 1 with DocumentEx

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

the class SvnPropertiesDiffViewer method setupHighlighting.

private void setupHighlighting(@NotNull DiffChange change, @NotNull Side side) {
    PropertyRecord record = change.getRecord();
    List<? extends LineFragment> fragments = change.getFragments();
    assert fragments != null;
    EditorEx editor = getEditor(side);
    DocumentEx document = editor.getDocument();
    int changeStartLine = change.getStartLine(side);
    for (LineFragment fragment : fragments) {
        List<DiffFragment> innerFragments = fragment.getInnerFragments();
        int startLine = side.getStartLine(fragment) + changeStartLine;
        int endLine = side.getEndLine(fragment) + changeStartLine;
        int start = document.getLineStartOffset(startLine);
        TextDiffType type = DiffUtil.getLineDiffType(fragment);
        DiffDrawUtil.createHighlighter(editor, startLine, endLine, type, innerFragments != null);
        // TODO: we can paint LineMarker here, but it looks ugly for small editors
        if (innerFragments != null) {
            for (DiffFragment innerFragment : innerFragments) {
                int innerStart = side.getStartOffset(innerFragment);
                int innerEnd = side.getEndOffset(innerFragment);
                TextDiffType innerType = DiffUtil.getDiffType(innerFragment);
                innerStart += start;
                innerEnd += start;
                DiffDrawUtil.createInlineHighlighter(editor, innerStart, innerEnd, innerType);
            }
        }
    }
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) LineFragment(com.intellij.diff.fragments.LineFragment) EditorEx(com.intellij.openapi.editor.ex.EditorEx) DiffFragment(com.intellij.diff.fragments.DiffFragment)

Example 2 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 3 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 4 with DocumentEx

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

the class EditorUtil method runBatchFoldingOperationOutsideOfBulkUpdate.

public static void runBatchFoldingOperationOutsideOfBulkUpdate(@NotNull Editor editor, @NotNull Runnable operation) {
    DocumentEx document = ObjectUtils.tryCast(editor.getDocument(), DocumentEx.class);
    if (document != null && document.isInBulkUpdate()) {
        MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect();
        disposeWithEditor(editor, connection);
        connection.subscribe(DocumentBulkUpdateListener.TOPIC, new DocumentBulkUpdateListener.Adapter() {

            @Override
            public void updateFinished(@NotNull Document doc) {
                if (doc == editor.getDocument()) {
                    editor.getFoldingModel().runBatchFoldingOperation(operation);
                    connection.disconnect();
                }
            }
        });
    } else {
        editor.getFoldingModel().runBatchFoldingOperation(operation);
    }
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) DocumentBulkUpdateListener(com.intellij.openapi.editor.ex.DocumentBulkUpdateListener)

Example 5 with DocumentEx

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

the class CaretImpl method moveToOffset.

@Override
public void moveToOffset(final int offset, final boolean locateBeforeSoftWrap) {
    assertIsDispatchThread();
    validateCallContext();
    if (mySkipChangeRequests) {
        return;
    }
    myEditor.getCaretModel().doWithCaretMerging(() -> {
        final LogicalPosition logicalPosition = myEditor.offsetToLogicalPosition(offset);
        CaretEvent event = moveToLogicalPosition(logicalPosition, locateBeforeSoftWrap, null, false);
        final LogicalPosition positionByOffsetAfterMove = myEditor.offsetToLogicalPosition(getOffset());
        if (!positionByOffsetAfterMove.equals(logicalPosition)) {
            StringBuilder debugBuffer = new StringBuilder();
            moveToLogicalPosition(logicalPosition, locateBeforeSoftWrap, debugBuffer, true);
            int actualOffset = getOffset();
            int textStart = Math.max(0, Math.min(offset, actualOffset) - 1);
            final DocumentEx document = myEditor.getDocument();
            int textEnd = Math.min(document.getTextLength() - 1, Math.max(offset, actualOffset) + 1);
            CharSequence text = document.getCharsSequence().subSequence(textStart, textEnd);
            int inverseOffset = myEditor.logicalPositionToOffset(logicalPosition);
            LogMessageEx.error(LOG, "caret moved to wrong offset. Please submit a dedicated ticket and attach current editor's text to it.", "Requested: offset=" + offset + ", logical position='" + logicalPosition + "' but actual: offset=" + actualOffset + ", logical position='" + myLogicalCaret + "' (" + positionByOffsetAfterMove + "). " + myEditor.dumpState() + "\ninterested text [" + textStart + ";" + textEnd + "): '" + text + "'\n debug trace: " + debugBuffer + "\nLogical position -> offset ('" + logicalPosition + "'->'" + inverseOffset + "')");
        }
        if (event != null) {
            myEditor.getCaretModel().fireCaretPositionChanged(event);
            EditorActionUtil.selectNonexpandableFold(myEditor);
        }
    });
}
Also used : CaretEvent(com.intellij.openapi.editor.event.CaretEvent) 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