disable unnecessary scrolling during lookup item insertion

This commit is contained in:
peter
2011-08-10 17:26:34 +02:00
parent 76188b9901
commit 56396944da
@@ -35,6 +35,7 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorModificationUtil;
import com.intellij.openapi.editor.SelectionModel;
import com.intellij.openapi.editor.actionSystem.TypedActionHandler;
import com.intellij.openapi.editor.ex.ScrollingModelEx;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import org.jetbrains.annotations.NotNull;
@@ -127,30 +128,37 @@ public class TypedHandler extends TypedActionHandlerBase {
SelectionModel sm = editor.getSelectionModel();
final boolean smartUndo = !sm.hasSelection() && !sm.hasBlockSelection() && process != null && process.isAutopopupCompletion();
final Runnable restore = CodeCompletionHandlerBase.rememberDocumentState(editor);
if (smartUndo) {
final ScrollingModelEx scrollingModel = (ScrollingModelEx)editor.getScrollingModel();
scrollingModel.accumulateViewportChanges();
try {
if (smartUndo) {
CommandProcessor.getInstance().executeCommand(editor.getProject(), new Runnable() {
@Override
public void run() {
lookup.performGuardedChange(baseChange);
}
}, null, "Just insert the completion char");
}
CommandProcessor.getInstance().executeCommand(editor.getProject(), new Runnable() {
@Override
public void run() {
lookup.performGuardedChange(baseChange);
if (smartUndo) {
AccessToken token = WriteAction.start();
try {
lookup.performGuardedChange(restore);
}
finally {
token.finish();
}
}
lookup.finishLookup(charTyped);
}
}, null, "Just insert the completion char");
}, null, "Undo inserting the completion char and select the item");
}
finally {
scrollingModel.flushViewportChanges();
}
CommandProcessor.getInstance().executeCommand(editor.getProject(), new Runnable() {
@Override
public void run() {
if (smartUndo) {
AccessToken token = WriteAction.start();
try {
lookup.performGuardedChange(restore);
}
finally {
token.finish();
}
}
lookup.finishLookup(charTyped);
}
}, null, "Undo inserting the completion char and select the item");
}
static CharFilter.Result getLookupAction(final char charTyped, final LookupImpl lookup) {