IDEA-163134 Editor sometimes hangs when moving parameters

This commit is contained in:
Alexey Kudravtsev
2016-10-27 15:17:37 +03:00
parent 9e42a92fa8
commit ca71226f81
2 changed files with 19 additions and 2 deletions
@@ -373,10 +373,12 @@ public class RangeMarkerTree<T extends RangeMarkerEx> extends IntervalTreeImpl<T
List<IntervalNode<T>> affected = new ArrayList<IntervalNode<T>>();
collectNodesToRetarget(getRoot(), start, end, affected);
if (affected.isEmpty()) return;
int shift = newBase - start;
// remove all first because findOrInsert can remove gced nodes which could interfere with not-yet-removed nodes
for (IntervalNode<T> node : affected) {
removeNode(node);
}
int shift = newBase - start;
for (IntervalNode<T> node : affected) {
node.setLeft(null);
node.setRight(null);
node.setParent(null);
@@ -1203,4 +1203,19 @@ public class RangeMarkerTest extends LightPlatformTestCase {
assertValidMarker(marker, 0, 9);
}
public void testMoveTextCrashes() {
DocumentEx doc = new DocumentImpl(StringUtil.repeat("blah", 1000));
Random random = new Random();
for(int i = 0; i < 10000; i++) {
int limit = doc.getTextLength() + 1;
int offset = random.nextInt(limit);
doc.createRangeMarker(offset, offset);
int startOffset = random.nextInt(limit);
int endOffset = random.nextInt(limit);
int targetOffset = random.nextInt(limit);
if (endOffset > startOffset && (targetOffset < startOffset || targetOffset > endOffset)) {
doc.moveText(startOffset, endOffset, targetOffset);
}
}
}
}