use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class FileDocumentManagerImplTest method testSaveDocument_DoNotSaveIfModStampEqualsToFile.
public void testSaveDocument_DoNotSaveIfModStampEqualsToFile() throws Exception {
final VirtualFile file = createFile();
final DocumentEx document = (DocumentEx) myDocumentManager.getDocument(file);
assertNotNull(file.toString(), document);
WriteCommandAction.runWriteCommandAction(myProject, () -> {
document.insertString(0, "zzz");
document.setModificationStamp(file.getModificationStamp());
});
getProject().getMessageBus().connect(getTestRootDisposable()).subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() {
@Override
public void beforeDocumentSaving(@NotNull Document documentToSave) {
assertNotSame(document, documentToSave);
}
});
myDocumentManager.saveDocument(document);
}
use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class FileDocumentManagerImplTest method testExternalReplaceWithTheSameText.
public void testExternalReplaceWithTheSameText() throws Exception {
final VirtualFile file = createFile();
long modificationStamp = file.getModificationStamp();
DocumentEx document = (DocumentEx) myDocumentManager.getDocument(file);
FileUtil.writeToFile(new File(file.getPath()), "xxx");
file.refresh(false, false);
assertNotNull(file.toString(), document);
assertNotSame(file.getModificationStamp(), modificationStamp);
assertEquals(file.getModificationStamp(), document.getModificationStamp());
}
use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class ApplyPatchChange method calcPatchInnerDifferences.
@Nullable
private static List<DiffFragment> calcPatchInnerDifferences(@NotNull PatchChangeBuilder.Hunk hunk, @NotNull ApplyPatchViewer viewer) {
LineRange deletionRange = hunk.getPatchDeletionRange();
LineRange insertionRange = hunk.getPatchInsertionRange();
if (deletionRange.isEmpty() || insertionRange.isEmpty())
return null;
try {
DocumentEx patchDocument = viewer.getPatchEditor().getDocument();
CharSequence deleted = DiffUtil.getLinesContent(patchDocument, deletionRange.start, deletionRange.end);
CharSequence inserted = DiffUtil.getLinesContent(patchDocument, insertionRange.start, insertionRange.end);
return ByWord.compare(deleted, inserted, ComparisonPolicy.DEFAULT, DumbProgressIndicator.INSTANCE);
} catch (DiffTooBigException ignore) {
return null;
}
}
use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class EditorImplTest method testChangingHighlightersInBulkModeListener.
public void testChangingHighlightersInBulkModeListener() throws Exception {
DocumentBulkUpdateListener.Adapter listener = new DocumentBulkUpdateListener.Adapter() {
@Override
public void updateFinished(@NotNull Document doc) {
if (doc == myEditor.getDocument()) {
myEditor.getMarkupModel().addRangeHighlighter(7, 8, 0, null, HighlighterTargetArea.EXACT_RANGE);
}
}
};
getProject().getMessageBus().connect(getTestRootDisposable()).subscribe(DocumentBulkUpdateListener.TOPIC, listener);
initText("abcdef");
DocumentEx document = (DocumentEx) myEditor.getDocument();
runWriteCommand(() -> {
DocumentUtil.executeInBulk(document, true, () -> {
document.insertString(3, "\n\n");
});
});
RangeHighlighter[] highlighters = myEditor.getMarkupModel().getAllHighlighters();
assertEquals(1, highlighters.length);
assertEquals(7, highlighters[0].getStartOffset());
assertEquals(8, highlighters[0].getEndOffset());
}
use of com.intellij.openapi.editor.ex.DocumentEx in project intellij-community by JetBrains.
the class EditorImplTest method testUpdatingCaretPositionAfterBulkMode.
public void testUpdatingCaretPositionAfterBulkMode() throws Exception {
initText("a<caret>bc");
runWriteCommand(() -> {
DocumentEx document = (DocumentEx) myEditor.getDocument();
DocumentUtil.executeInBulk(document, true, () -> {
// we're changing number of visual lines, and invalidating text layout for caret line
document.insertString(0, "\n ");
});
});
checkResultByText("\n a<caret>bc");
}
Aggregations