From 75113532b3acf8fbc0dc36e8e1c67e1477a3a570 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 18 Apr 2011 15:33:04 +0200 Subject: [PATCH] wrap auto-insertion in a command, API-ready MatchedLookupElement --- .../completion/CodeCompletionHandlerBase.java | 10 +++++++++- .../completion/CompletionProgressIndicator.java | 4 ++-- .../completion/impl/MatchedLookupElement.java | 7 ++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java index a99115b407d0..4511addf6171 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java @@ -426,7 +426,15 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler { final Runnable restorePrefix = rememberDocumentState(indicator.getEditor()); final LookupElement item = ((AutoCompletionDecision.InsertItem)decision).getElement(); - indicator.getLookup().finishLookup(Lookup.AUTO_INSERT_SELECT_CHAR, item); + CommandProcessor.getInstance().executeCommand(indicator.getProject(), new Runnable() { + @Override + public void run() { + indicator.setMergeCommand(); + indicator.getLookup().finishLookup(Lookup.AUTO_INSERT_SELECT_CHAR, item); + } + }, "Autocompletion", null); + + // the insert handler may have started a live template with completion if (CompletionService.getCompletionService().getCurrentCompletion() == null && diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java index bed4ba3b109f..5ddca1d23721 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CompletionProgressIndicator.java @@ -300,7 +300,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement }); } - private void setMergeCommand() { + public void setMergeCommand() { CommandProcessor.getInstance().setCurrentCommandGroupId(getCompletionCommandName()); } @@ -370,7 +370,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement LOG.assertTrue(myParameters.getPosition().isValid()); - myItemSorters.put(item.getDelegate(), item.getSorter()); + myItemSorters.put(item.getDelegate(), (CompletionSorterImpl) item.getSorter()); myLookup.addItem(item.getDelegate(), item.getPrefixMatcher()); myCount++; if (unitTestMode) return; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/MatchedLookupElement.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/MatchedLookupElement.java index e707a3493548..74fb8c7b46b3 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/MatchedLookupElement.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/impl/MatchedLookupElement.java @@ -15,6 +15,7 @@ */ package com.intellij.codeInsight.completion.impl; +import com.intellij.codeInsight.completion.CompletionSorter; import com.intellij.codeInsight.completion.PrefixMatcher; import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.codeInsight.lookup.LookupElementDecorator; @@ -26,9 +27,9 @@ import com.intellij.openapi.util.ClassConditionKey; public class MatchedLookupElement extends LookupElementDecorator { public static final ClassConditionKey CLASS_CONDITION_KEY = ClassConditionKey.create(MatchedLookupElement.class); private final PrefixMatcher myMatcher; - private final CompletionSorterImpl mySorter; + private final CompletionSorter mySorter; - MatchedLookupElement(LookupElement delegate, PrefixMatcher matcher, CompletionSorterImpl sorter) { + MatchedLookupElement(LookupElement delegate, PrefixMatcher matcher, CompletionSorter sorter) { super(delegate); myMatcher = matcher; mySorter = sorter; @@ -38,7 +39,7 @@ public class MatchedLookupElement extends LookupElementDecorator return myMatcher; } - public CompletionSorterImpl getSorter() { + public CompletionSorter getSorter() { return mySorter; }