use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.
the class PsiDocumentManagerBase method beforeDocumentChange.
@Override
public void beforeDocumentChange(@NotNull DocumentEvent event) {
if (myStopTrackingDocuments || myProject.isDisposed())
return;
final Document document = event.getDocument();
VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(document);
boolean isRelevant = virtualFile != null && isRelevant(virtualFile);
if (document instanceof DocumentImpl && !myUncommittedInfos.containsKey(document)) {
myUncommittedInfos.put(document, new UncommittedInfo((DocumentImpl) document));
}
final FileViewProvider viewProvider = getCachedViewProvider(document);
boolean inMyProject = viewProvider != null && viewProvider.getManager() == myPsiManager;
if (!isRelevant || !inMyProject) {
return;
}
final List<PsiFile> files = viewProvider.getAllFiles();
PsiFile psiCause = null;
for (PsiFile file : files) {
if (file == null) {
throw new AssertionError("View provider " + viewProvider + " (" + viewProvider.getClass() + ") returned null in its files array: " + files + " for file " + viewProvider.getVirtualFile());
}
if (PsiToDocumentSynchronizer.isInsideAtomicChange(file)) {
psiCause = file;
}
}
if (psiCause == null) {
beforeDocumentChangeOnUnlockedDocument(viewProvider);
}
((SingleRootFileViewProvider) viewProvider).beforeDocumentChanged(psiCause);
}
use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.
the class FoldingStressTest method stress.
private static void stress(final int len) {
DocumentImpl doc = new DocumentImpl("0123456789\n123456789\n23456789");
Editor editor = EditorFactory.getInstance().createEditor(doc);
try {
final FoldingModel model = editor.getFoldingModel();
model.runBatchFoldingOperation(() -> {
addAndCollapseFoldRegion(model, 0, len, "/*...*/");
addAndCollapseFoldRegion(model, len + 2, len + 4, "/*...*/");
});
for (int line = 0; line <= 3; line++) {
for (int column = 0; column <= 100; column++) {
LogicalPosition log = new LogicalPosition(line, column);
editor.logicalToVisualPosition(log);
}
}
} finally {
EditorFactory.getInstance().releaseEditor(editor);
}
}
use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.
the class DocumentTest method testModificationInsideCommandAssertion.
public void testModificationInsideCommandAssertion() {
CommandProcessor commandProcessor = CommandProcessor.getInstance();
assertTrue(!commandProcessor.isUndoTransparentActionInProgress() && commandProcessor.getCurrentCommand() == null);
final Document doc = new DocumentImpl("xxx");
mustThrow(() -> doc.insertString(1, "x"));
mustThrow(() -> doc.deleteString(1, 2));
mustThrow(() -> doc.replaceString(1, 2, "s"));
WriteCommandAction.runWriteCommandAction(getProject(), () -> doc.insertString(1, "s"));
WriteCommandAction.runWriteCommandAction(getProject(), () -> doc.deleteString(1, 2));
WriteCommandAction.runWriteCommandAction(getProject(), () -> doc.replaceString(1, 2, "xxx"));
WriteCommandAction.runWriteCommandAction(getProject(), () -> doc.setText("sss"));
DocumentImpl console = new DocumentImpl("xxxx", true);
// need no stinking command
console.insertString(1, "s");
console.deleteString(1, 2);
console.replaceString(1, 2, "xxx");
console.setText("sss");
}
use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.
the class DocumentTest method testCorrectlyAddingAndRemovingListeners.
public void testCorrectlyAddingAndRemovingListeners() throws Exception {
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
final Document doc = new DocumentImpl("");
final StringBuilder b = new StringBuilder();
doc.addDocumentListener(new DocumentAdapter() {
@Override
public void beforeDocumentChange(DocumentEvent e) {
b.append("before1 ");
}
@Override
public void documentChanged(DocumentEvent e) {
b.append("after1 ");
}
});
doc.addDocumentListener(new DocumentAdapter() {
@Override
public void beforeDocumentChange(DocumentEvent event) {
doc.removeDocumentListener(this);
}
});
doc.addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
doc.removeDocumentListener(this);
}
});
doc.addDocumentListener(new DocumentAdapter() {
@Override
public void beforeDocumentChange(DocumentEvent e) {
b.append("before2 ");
}
@Override
public void documentChanged(DocumentEvent e) {
b.append("after2 ");
}
});
doc.setText("foo");
assertEquals("before2 before1 after1 after2 ", b.toString());
}
}.execute().throwException();
}
use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.
the class EditorPlaceHolder method setContent.
public void setContent(final DiffContent content) {
runRegisteredDisposables();
myContent = content;
if (myContent != null) {
Document document = myContent.getDocument();
if (myContent.isBinary() || document == null || myContent.getContentType() instanceof UIBasedFileType) {
final VirtualFile file = myContent.getFile();
if (file != null) {
final FileEditorProvider[] providers = FileEditorProviderManager.getInstance().getProviders(getProject(), file);
if (providers.length > 0) {
myFileEditor = providers[0].createEditor(getProject(), file);
if (myFileEditor instanceof TextEditor) {
myEditor = (EditorEx) ((TextEditor) myFileEditor).getEditor();
ContentDocumentListener.install(myContent, this);
}
myFileEditorProvider = providers[0];
addDisposable(new Disposable() {
@Override
public void dispose() {
myFileEditorProvider.disposeEditor(myFileEditor);
myFileEditor = null;
myFileEditorProvider = null;
myEditor = null;
}
});
} else {
document = new DocumentImpl("Can not show", true);
final EditorFactory editorFactory = EditorFactory.getInstance();
myEditor = DiffUtil.createEditor(document, getProject(), true, content.getContentType());
addDisposable(new Disposable() {
public void dispose() {
editorFactory.releaseEditor(myEditor);
myEditor = null;
}
});
}
}
} else {
final EditorFactory editorFactory = EditorFactory.getInstance();
myEditor = DiffUtil.createEditor(document, getProject(), false, content.getContentType());
addDisposable(new Disposable() {
public void dispose() {
editorFactory.releaseEditor(myEditor);
myEditor = null;
}
});
ContentDocumentListener.install(myContent, this);
}
}
fireContentChanged();
}
Aggregations