Merge branch 'master' of git@git.labs.intellij.net:idea/community

This commit is contained in:
Eugene Kudelevsky
2010-12-08 16:56:47 +03:00
3 changed files with 20 additions and 34 deletions
@@ -56,9 +56,6 @@ public class SoftWrapModelImpl implements SoftWrapModelEx, PrioritizedDocumentLi
private static final Logger LOG = Logger.getInstance("#" + SoftWrapModelImpl.class.getName());
/** Upper boundary of time interval to check editor settings. */
private static final long EDITOR_SETTINGS_CHECK_PERIOD_MILLIS = 10000;
private final OffsetToLogicalTask myOffsetToLogicalTask = new OffsetToLogicalTask();
private final VisualToLogicalTask myVisualToLogicalTask = new VisualToLogicalTask();
private final LogicalToVisualTask myLogicalToVisualTask = new LogicalToVisualTask();
@@ -77,9 +74,7 @@ public class SoftWrapModelImpl implements SoftWrapModelEx, PrioritizedDocumentLi
private final EditorEx myEditor;
/** Holds number of 'active' calls, i.e. number of methods calls of the current object within the current call stack. */
private int myActive;
/** Holds timestamp of the last editor settings check. */
private long myLastSettingsCheckTimeMillis;
private Boolean myLastUseSoftWraps;
private boolean myUseSoftWraps;
public SoftWrapModelImpl(@NotNull EditorEx editor) {
this(editor, new SoftWrapsStorage(), new CompositeSoftWrapPainter(editor));
@@ -115,13 +110,18 @@ public class SoftWrapModelImpl implements SoftWrapModelEx, PrioritizedDocumentLi
myDocumentListeners.add(myApplianceManager);
myFoldListeners.add(myApplianceManager);
applianceManager.addListener(myVisualSizeManager);
myUseSoftWraps = myEditor.getSettings().isUseSoftWraps();
}
/**
* Called on editor settings change. Current model is expected to drop all cached information about the settings if any.
*/
public void reinitSettings() {
myLastUseSoftWraps = null;
boolean softWrapsUsedBefore = myUseSoftWraps;
myUseSoftWraps = myEditor.getSettings().isUseSoftWraps();
if (myUseSoftWraps && !softWrapsUsedBefore) {
myApplianceManager.reset();
}
}
public boolean isSoftWrappingEnabled() {
@@ -140,13 +140,7 @@ public class SoftWrapModelImpl implements SoftWrapModelEx, PrioritizedDocumentLi
return false;
}
// Profiling shows that editor settings lookup have impact at overall performance if called often.
// Hence, we cache value used last time.
if (myLastUseSoftWraps != null && System.currentTimeMillis() - myLastSettingsCheckTimeMillis <= EDITOR_SETTINGS_CHECK_PERIOD_MILLIS) {
return myLastUseSoftWraps == Boolean.TRUE;
}
myLastSettingsCheckTimeMillis = System.currentTimeMillis();
return myLastUseSoftWraps = myEditor.getSettings().isUseSoftWraps();
return myUseSoftWraps;
}
@Nullable
@@ -523,10 +517,6 @@ public class SoftWrapModelImpl implements SoftWrapModelEx, PrioritizedDocumentLi
myStorage.removeAll();
}
public void refreshSettings() {
myLastSettingsCheckTimeMillis = 0;
}
public SoftWrapApplianceManager getApplianceManager() {
return myApplianceManager;
}
@@ -553,7 +543,8 @@ public class SoftWrapModelImpl implements SoftWrapModelEx, PrioritizedDocumentLi
task, myDataMapper, myEditor.getDocument().getText(), Arrays.toString(myEditor.getFoldingModel().fetchTopLevel())), e);
}
myDataMapper.release();
myApplianceManager.release();
myApplianceManager.reset();
myStorage.removeAll();
try {
task.run(true);
}
@@ -80,7 +80,6 @@ public class SoftWrapApplianceManager implements FoldingListener, DocumentListen
private boolean myCustomIndentUsedLastTime;
private int myCustomIndentValueUsedLastTime;
private int myVisibleAreaWidth;
private long myLastDocumentStamp;
private boolean myInProgress;
public SoftWrapApplianceManager(@NotNull SoftWrapsStorage storage,
@@ -100,9 +99,13 @@ public class SoftWrapApplianceManager implements FoldingListener, DocumentListen
recalculateIfNecessary();
}
public void release() {
public void reset() {
myEventsStorage.release();
myEventsStorage.add(myEditor.getDocument(), new IncrementalCacheUpdateEvent(myEditor.getDocument()));
}
public void release() {
myEventsStorage.release();
myLineWrapPositionStrategy = null;
}
@@ -112,7 +115,6 @@ public class SoftWrapApplianceManager implements FoldingListener, DocumentListen
return;
}
myLastDocumentStamp = myEditor.getDocument().getModificationStamp();
// There is a possible case that new dirty regions are encountered during processing, hence, we iterate on regions snapshot here.
List<IncrementalCacheUpdateEvent> events = new ArrayList<IncrementalCacheUpdateEvent>(myEventsStorage.getEvents());
myEventsStorage.release();
@@ -586,18 +588,12 @@ public class SoftWrapApplianceManager implements FoldingListener, DocumentListen
myContext.softWrapStartOffset = softWrap.getStart() + 1;
}
public void recalculateIfNecessary() {
recalculateIfNecessary(myEditor.getDocument().getModificationStamp());
}
/**
* There is a possible case that we need to reparse the whole document (e.g. visible area width is changed or user-defined
* soft wrap indent is changed etc). This method encapsulates that logic, i.e. it checks if necessary conditions are satisfied
* and updates internal state as necessary.
*
* @param documentStamp document modification stamp to use if document was changed while soft wrapping was off
*/
public void recalculateIfNecessary(long documentStamp) {
public void recalculateIfNecessary() {
if (myInProgress) {
return;
}
@@ -615,14 +611,13 @@ public class SoftWrapApplianceManager implements FoldingListener, DocumentListen
// Check if we need to recalculate soft wraps due to visible area width change.
int currentVisibleAreaWidth = myWidthProvider.getVisibleAreaWidth();
if (!indentChanged && myVisibleAreaWidth == currentVisibleAreaWidth && documentStamp == myLastDocumentStamp) {
if (!indentChanged && myVisibleAreaWidth == currentVisibleAreaWidth) {
recalculateSoftWraps(); // Recalculate existing dirty regions if any.
return;
}
// Drop information about processed lines then.
myEventsStorage.release();
myEventsStorage.add(myEditor.getDocument(), new IncrementalCacheUpdateEvent(myEditor.getDocument()));
reset();
myStorage.removeAll();
myVisibleAreaWidth = currentVisibleAreaWidth;
recalculateSoftWraps();
@@ -748,7 +743,7 @@ public class SoftWrapApplianceManager implements FoldingListener, DocumentListen
@Override
public void documentChanged(DocumentEvent event) {
recalculateIfNecessary(event.getOldTimeStamp());
recalculateIfNecessary();
}
/**
@@ -596,7 +596,7 @@ public class SoftWrapApplianceOnDocumentModificationTest extends AbstractEditorP
init(fileText);
myEditor.getSettings().setUseSoftWraps(true);
SoftWrapModelImpl model = (SoftWrapModelImpl)myEditor.getSoftWrapModel();
model.refreshSettings();
model.reinitSettings();
SoftWrapApplianceManager applianceManager = model.getApplianceManager();
applianceManager.setWidthProvider(new SoftWrapApplianceManager.VisibleAreaWidthProvider() {