mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
persistent rangemarker update for small documents
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user