EA-29579 - assert: CaretModelImpl.moveToOffset

Don't move caret during expanding fold region from 'move caret' reqest
This commit is contained in:
Denis.Zhdanov
2011-12-15 16:04:49 +04:00
parent 2bc9af7d29
commit ff98bf456e
4 changed files with 34 additions and 21 deletions
@@ -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);
}
@@ -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));
}
@@ -513,7 +513,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener,
}
};
myEditor.getFoldingModel().runBatchFoldingOperation(runnable);
myEditor.getFoldingModel().runBatchFoldingOperation(runnable, false);
}
myEditor.setLastColumnNumber(myLogicalCaret.column);
@@ -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;