persistent rangemarker update for small documents

This commit is contained in:
Alexey Kudravtsev
2012-03-30 18:35:12 +04:00
parent b04ea23c1a
commit 996cefbf94
2 changed files with 20 additions and 4 deletions
@@ -69,19 +69,24 @@ class PersistentRangeMarker extends RangeMarkerImpl {
private boolean translateViaDiff(final DocumentEventImpl event) {
try {
myStartLine = event.translateLineViaDiffStrict(myStartLine);
if (myStartLine < 0 || myStartLine >= getDocument().getLineCount()) {
DocumentEx document = getDocument();
if (myStartLine < 0 || myStartLine >= document.getLineCount()) {
invalidate(event);
}
else {
setIntervalStart(getDocument().getLineStartOffset(myStartLine) + myStartColumn);
int start = document.getLineStartOffset(myStartLine) + myStartColumn;
if (start >= document.getTextLength()) return false;
setIntervalStart(start);
}
myEndLine = event.translateLineViaDiffStrict(myEndLine);
if (myEndLine < 0 || myEndLine >= getDocument().getLineCount()) {
if (myEndLine < 0 || myEndLine >= document.getLineCount()) {
invalidate(event);
}
else {
setIntervalEnd(getDocument().getLineStartOffset(myEndLine) + myEndColumn);
int end = document.getLineStartOffset(myEndLine) + myEndColumn;
if (end > document.getTextLength()) return false;
setIntervalEnd(end);
}
return true;
}
@@ -1045,4 +1045,15 @@ public class RangeMarkerTest extends LightPlatformTestCase {
EditorFactory.getInstance().releaseEditor(editor);
}
}
public void testPersistent() throws Exception {
String text = "xxx\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
Document document = EditorFactory.getInstance().createDocument(text);
int startOffset = text.indexOf('z');
int endOffset = text.lastIndexOf('z');
RangeMarker marker = document.createRangeMarker(startOffset, endOffset, true);
document.replaceString(startOffset+1, endOffset-1, "ccc");
assertTrue(marker.isValid());
}
}