diff --git a/platform/platform-api/src/com/intellij/openapi/editor/FoldingModel.java b/platform/platform-api/src/com/intellij/openapi/editor/FoldingModel.java index 47b760169793..35c70de0c2d2 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/FoldingModel.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/FoldingModel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 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. @@ -74,5 +74,15 @@ public interface FoldingModel { */ void runBatchFoldingOperation(@NotNull Runnable operation); + /** + * Runs an operation which is allowed to modify fold regions in the editor by calling + * {@link #addFoldRegion(int, int, String)} and {@link #removeFoldRegion(FoldRegion)}. + * + * @param operation the operation to execute. + * @param moveCaretFromCollapsedRegion flag that identifies whether caret position should be changed if it's located inside + * collapsed fold region after the operation + */ + void runBatchFoldingOperation(@NotNull Runnable operation, boolean moveCaretFromCollapsedRegion); + void runBatchFoldingOperationDoNotCollapseCaret(@NotNull Runnable operation); } diff --git a/platform/platform-impl/src/com/intellij/diagnostic/LogMessageEx.java b/platform/platform-impl/src/com/intellij/diagnostic/LogMessageEx.java index 2a3cf4711105..f299f783b408 100644 --- a/platform/platform-impl/src/com/intellij/diagnostic/LogMessageEx.java +++ b/platform/platform-impl/src/com/intellij/diagnostic/LogMessageEx.java @@ -138,7 +138,7 @@ public class LogMessageEx extends LogMessage { if (details.length > 0 && detailsBuffer.length() > 0) { detailsBuffer.setLength(detailsBuffer.length() - 1); } - Attachment attachment = detailsBuffer.length() > 0 ? new Attachment("current context", detailsBuffer.toString()) : null; + Attachment attachment = detailsBuffer.length() > 0 ? new Attachment("current-context.txt", detailsBuffer.toString()) : null; logger.error(createEvent(message, ExceptionUtil.getThrowableText(new Throwable()), null, null, attachment)); } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java index 6560ad8b1cdd..7f613687fcd2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretModelImpl.java @@ -513,7 +513,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, } }; - myEditor.getFoldingModel().runBatchFoldingOperation(runnable); + myEditor.getFoldingModel().runBatchFoldingOperation(runnable, false); } myEditor.setLastColumnNumber(myLogicalCaret.column); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java index 6fd0a67a4e0c..1adca403dcd4 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingModelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 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. @@ -188,10 +188,15 @@ public class FoldingModelImpl implements FoldingModelEx, PrioritizedDocumentList @Override public void runBatchFoldingOperation(@NotNull Runnable operation) { - runBatchFoldingOperation(operation, false); + runBatchFoldingOperation(operation, false, true); } - private void runBatchFoldingOperation(final Runnable operation, final boolean dontCollapseCaret) { + @Override + public void runBatchFoldingOperation(@NotNull Runnable operation, boolean moveCaret) { + runBatchFoldingOperation(operation, false, moveCaret); + } + + private void runBatchFoldingOperation(final Runnable operation, final boolean dontCollapseCaret, final boolean moveCaret) { assertIsDispatchThread(); boolean oldDontCollapseCaret = myDoNotCollapseCaret; myDoNotCollapseCaret |= dontCollapseCaret; @@ -207,7 +212,7 @@ public class FoldingModelImpl implements FoldingModelEx, PrioritizedDocumentList if (!oldBatchFlag) { if (myFoldRegionsProcessed) { - notifyBatchFoldingProcessingDone(); + notifyBatchFoldingProcessingDone(moveCaret); myFoldRegionsProcessed = false; } myIsBatchFoldingProcessing = false; @@ -217,7 +222,7 @@ public class FoldingModelImpl implements FoldingModelEx, PrioritizedDocumentList @Override public void runBatchFoldingOperationDoNotCollapseCaret(@NotNull final Runnable operation) { - runBatchFoldingOperation(operation, true); + runBatchFoldingOperation(operation, true, true); } public void flushCaretShift() { @@ -337,11 +342,7 @@ public class FoldingModelImpl implements FoldingModelEx, PrioritizedDocumentList notifyListenersOnFoldRegionStateChange(region); } - private void notifyBatchFoldingProcessingDone() { - doNotifyBatchFoldingProcessingDone(); - } - - private void doNotifyBatchFoldingProcessingDone() { + private void notifyBatchFoldingProcessingDone(final boolean moveCaretFromCollapsedRegion) { myFoldTree.rebuild(); for (FoldingListener listener : myListeners) { @@ -390,14 +391,16 @@ public class FoldingModelImpl implements FoldingModelEx, PrioritizedDocumentList boolean oldCaretPositionSaved = myCaretPositionSaved; - if (offsetToUse >= 0) { - myEditor.getCaretModel().moveToOffset(offsetToUse); - } - else if (column != -1) { - myEditor.getCaretModel().moveToLogicalPosition(new LogicalPosition(line, column)); - } - else { - myEditor.getCaretModel().moveToLogicalPosition(caretPosition); + if (moveCaretFromCollapsedRegion) { + if (offsetToUse >= 0) { + myEditor.getCaretModel().moveToOffset(offsetToUse); + } + else if (column != -1) { + myEditor.getCaretModel().moveToLogicalPosition(new LogicalPosition(line, column)); + } + else { + myEditor.getCaretModel().moveToLogicalPosition(caretPosition); + } } myCaretPositionSaved = oldCaretPositionSaved;