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