use of com.intellij.openapi.editor.ex.RangeMarkerEx in project intellij-community by JetBrains.
the class RangeMarkerTest method testMoveTextToTheBeginningRetargetsMarkers.
public void testMoveTextToTheBeginningRetargetsMarkers() throws Exception {
RangeMarkerEx marker1 = createMarker("01234567890", 5, 5);
DocumentEx document = (DocumentEx) marker1.getDocument();
RangeMarker marker2 = document.createRangeMarker(5, 7);
document.moveText(4, 7, 1);
assertEquals("04561237890", document.getText());
assertValidMarker(marker1, 2, 2);
assertValidMarker(marker2, 2, 4);
}
use of com.intellij.openapi.editor.ex.RangeMarkerEx in project intellij-community by JetBrains.
the class RangeMarkerTest method testRandomEdit_NoCommand.
public void testRandomEdit_NoCommand() {
final int N = 100;
final Random gen = new Random();
int N_TRIES = Timings.adjustAccordingToMySpeed(7000, false);
System.out.println("N_TRIES = " + N_TRIES);
DocumentEx document = null;
for (int tryn = 0; tryn < N_TRIES; tryn++) {
((UndoManagerImpl) UndoManager.getInstance(getProject())).flushCurrentCommandMerger();
((UndoManagerImpl) UndoManager.getGlobalInstance()).flushCurrentCommandMerger();
if (document != null) {
((UndoManagerImpl) UndoManager.getInstance(getProject())).clearUndoRedoQueueInTests(document);
((UndoManagerImpl) UndoManager.getGlobalInstance()).clearUndoRedoQueueInTests(document);
}
if (tryn % 10000 == 0) {
System.out.println(tryn);
}
document = (DocumentEx) EditorFactory.getInstance().createDocument(StringUtil.repeatSymbol(' ', N));
final DocumentEx finalDocument = document;
new WriteCommandAction(getProject()) {
@Override
protected void run(@NotNull Result result) throws Exception {
List<Pair<RangeMarker, TextRange>> adds = new ArrayList<>();
List<Pair<RangeMarker, TextRange>> dels = new ArrayList<>();
List<Trinity<Integer, Integer, Integer>> edits = new ArrayList<>();
try {
for (int i = 0; i < 30; i++) {
int x = gen.nextInt(N);
int y = x + gen.nextInt(N - x);
RangeMarkerEx r = (RangeMarkerEx) finalDocument.createRangeMarker(x, y);
adds.add(Pair.create(r, TextRange.create(r)));
}
for (int i = 0; i < 10; i++) {
int offset = gen.nextInt(finalDocument.getTextLength());
if (gen.nextBoolean()) {
int length = gen.nextInt(5);
edits.add(Trinity.create(offset, 0, length));
finalDocument.insertString(offset, StringUtil.repeatSymbol(' ', length));
} else {
int length = gen.nextInt(finalDocument.getTextLength() - offset);
edits.add(Trinity.create(offset, length, 0));
finalDocument.deleteString(offset, offset + length);
}
}
List<Pair<RangeMarker, TextRange>> candidates = new ArrayList<>(adds);
while (!candidates.isEmpty()) {
int size = candidates.size();
int x = gen.nextInt(size);
Pair<RangeMarker, TextRange> c = candidates.remove(x);
RangeMarkerEx r = (RangeMarkerEx) c.first;
assertEquals(size - 1, candidates.size());
dels.add(c);
r.dispose();
}
} catch (AssertionError e) {
String s = "adds: ";
for (Pair<RangeMarker, TextRange> c : adds) {
TextRange t = c.second;
s += t.getStartOffset() + "," + t.getEndOffset() + ", ";
}
s += "\nedits: ";
for (Trinity<Integer, Integer, Integer> edit : edits) {
s += edit.first + "," + edit.second + "," + edit.third + ", ";
}
s += "\ndels: ";
for (Pair<RangeMarker, TextRange> c : dels) {
int index = adds.indexOf(c);
assertSame(c, adds.get(index));
s += index + ", ";
}
System.err.println(s);
throw e;
}
}
}.execute();
}
}
use of com.intellij.openapi.editor.ex.RangeMarkerEx in project intellij-community by JetBrains.
the class RangeMarkerTest method _testRandomAddRemove.
public void _testRandomAddRemove() {
int N = 100;
for (int ti = 0; ; ti++) {
if (ti % 10000 == 0)
System.out.println(ti);
DocumentEx document = (DocumentEx) EditorFactory.getInstance().createDocument(StringUtil.repeatSymbol(' ', N));
Random gen = new Random();
List<Pair<RangeMarker, TextRange>> adds = new ArrayList<>();
List<Pair<RangeMarker, TextRange>> dels = new ArrayList<>();
try {
for (int i = 0; i < 30; i++) {
int x = gen.nextInt(N);
int y = x + gen.nextInt(N - x);
if (gen.nextBoolean()) {
x = 0;
y = document.getTextLength();
}
RangeMarkerEx r = (RangeMarkerEx) document.createRangeMarker(x, y);
adds.add(Pair.create(r, TextRange.create(r)));
}
List<Pair<RangeMarker, TextRange>> candidates = new ArrayList<>(adds);
while (!candidates.isEmpty()) {
int size = candidates.size();
int x = gen.nextInt(size);
Pair<RangeMarker, TextRange> c = candidates.remove(x);
RangeMarkerEx r = (RangeMarkerEx) c.first;
assertEquals(size - 1, candidates.size());
dels.add(c);
r.dispose();
}
} catch (AssertionError e) {
String s = "adds: ";
for (Pair<RangeMarker, TextRange> c : adds) {
TextRange t = c.second;
s += t.getStartOffset() + "," + t.getEndOffset() + ", ";
}
s += "\ndels: ";
for (Pair<RangeMarker, TextRange> c : dels) {
int index = adds.indexOf(c);
assertSame(c, adds.get(index));
s += index + ", ";
}
System.err.println(s);
throw e;
}
}
}
use of com.intellij.openapi.editor.ex.RangeMarkerEx in project intellij-community by JetBrains.
the class RangeMarkerTest method testMoveTextRetargetsMarkers.
public void testMoveTextRetargetsMarkers() throws Exception {
RangeMarkerEx marker1 = createMarker("01234567890", 1, 3);
DocumentEx document = (DocumentEx) marker1.getDocument();
RangeMarker marker2 = document.createRangeMarker(2, 4);
document.moveText(0, 5, 8);
assertEquals("56701234890", document.getText());
assertValidMarker(marker1, 4, 6);
assertValidMarker(marker2, 5, 7);
}
use of com.intellij.openapi.editor.ex.RangeMarkerEx in project intellij-community by JetBrains.
the class RangeMarkerTest method testMoveText2.
public void testMoveText2() throws Exception {
RangeMarkerEx marker1 = createMarker(StringUtil.repeat(" ", 100), 0, 0);
DocumentEx document = (DocumentEx) marker1.getDocument();
RangeMarker marker2 = document.createRangeMarker(49, 49);
document.moveText(0, 1, 49);
marker1.dispose();
marker2.dispose();
}
Aggregations