IDEA-76537 Detected invalid soft wraps recalculation

Soft wraps cache is correctly flushed on complete recalculation
This commit is contained in:
Denis.Zhdanov
2011-11-22 19:29:26 +03:00
parent 1a0d59d8dd
commit 55bb42dc0c
7 changed files with 58 additions and 8 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -228,8 +228,8 @@ class CacheEntry implements Comparable<CacheEntry>, Cloneable {
@Override
public String toString() {
return "visual line: " + visualLine + ", offsets: " + startOffset + "-" + endOffset + ", fold regions: "
+ Arrays.toString(myFoldingData.getValues()) + ", tab data: " + myTabPositions;
return System.identityHashCode(this) + "=visual line: " + visualLine + ", offsets: " + startOffset + "-" + endOffset
+ ", fold regions: " + Arrays.toString(myFoldingData.getValues()) + ", tab data: " + myTabPositions;
}
@Override
@@ -482,6 +482,13 @@ public class CachingSoftWrapDataMapper implements SoftWrapDataMapper, SoftWrapAw
myBeforeChangeState.cacheShouldBeUpdated = false;
}
@Override
public void reset() {
myCache.clear();
myAffectedByUpdateCacheEntries.clear();
myNotAffectedByUpdateTailCacheEntries.clear();
}
@SuppressWarnings({"UseOfSystemOutOrSystemErr", "UnusedDeclaration", "CallToPrintStackTrace"})
private void dumpCache() {
Document document = myEditor.getDocument();
@@ -542,7 +549,7 @@ public class CachingSoftWrapDataMapper implements SoftWrapDataMapper, SoftWrapAw
int softWrapIndex = myStorage.getSoftWrapIndex(offset);
if (softWrapIndex >= 0) {
softWrapIndex++; // We want to process only soft wraps which offsets strictly more than the given one.
softWrapIndex++; // We want to process only soft wraps which offsets are strictly more than the given one.
}
else {
softWrapIndex = -softWrapIndex - 1;
@@ -118,6 +118,9 @@ public class SoftWrapApplianceManager implements SoftWrapFoldingListener, Docume
public void reset() {
myEventsStorage.release();
myEventsStorage.add(myEditor.getDocument(), new IncrementalCacheUpdateEvent(myEditor.getDocument()));
for (SoftWrapAwareDocumentParsingListener listener : myListeners) {
listener.reset();
}
}
public void release() {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -120,4 +120,9 @@ interface SoftWrapAwareDocumentParsingListener {
* should be rolled back if this param value is <code>false</code>
*/
void onRecalculationEnd(@NotNull IncrementalCacheUpdateEvent event, boolean normal);
/**
* Callback for asking to drop all cached information (if any).
*/
void reset();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -120,4 +120,8 @@ public class SoftWrapAwareVisualSizeManager implements SoftWrapAwareDocumentPars
@Override
public void revertToOffset(int offset, int visualLine) {
}
@Override
public void reset() {
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,7 +31,7 @@ class TabData implements Cloneable {
@Override
public String toString() {
return offset + ", width: " + widthInColumns;
return "[" + offset + ", width: " + widthInColumns + "]";
}
@Override
@@ -817,6 +817,37 @@ public class SoftWrapApplianceOnDocumentModificationTest extends AbstractEditorP
((EditorImpl)myEditor).setPrefixTextAndAttributes(" ", new TextAttributes());
myEditor.getCaretModel().moveToOffset(text.length());
}
public void testSoftWrapCacheReset() throws IOException {
// Inspired by IDEA-76537 - the point is to drop cached document info on complete soft wraps recalculation
String text =
"\t first line\n" +
"\t second line\n" +
"\t third line";
// Make soft wraps to build a document info cache.
init(300, text);
// Modify document while soft wraps processing is off.
final EditorSettings settings = getEditor().getSettings();
settings.setUseSoftWraps(false);
int startOffset = text.indexOf("\t third") - 1;
getEditor().getDocument().deleteString(startOffset, text.length());
// Enable soft wraps and ensure that the cache is correctly re-built.
settings.setUseSoftWraps(true);
getEditor().getCaretModel().moveToOffset(getEditor().getDocument().getTextLength());
type("\n test");
final int offset = getEditor().getDocument().getTextLength() - 1;
final LogicalPosition logicalPosition = getEditor().offsetToLogicalPosition(offset);
assertEquals(offset, getEditor().logicalPositionToOffset(logicalPosition));
final VisualPosition visualPosition = getEditor().offsetToVisualPosition(offset);
assertEquals(visualPosition, getEditor().logicalToVisualPosition(logicalPosition));
assertEquals(logicalPosition, getEditor().visualToLogicalPosition(visualPosition));
}
private void init(final int visibleWidth, @NotNull String fileText) throws IOException {
init(visibleWidth, fileText, TestFileType.TEXT);