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);
}
}
}
}
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);
}
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();
}
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);
}
}
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);
}
});
}
Aggregations