From bd8087c9367e00fec28430eeb061a14f2bed2f48 Mon Sep 17 00:00:00 2001 From: Andrey Dernov Date: Wed, 6 Jul 2016 13:27:21 +0300 Subject: [PATCH] IDEA-158139 Make TemplateExpressionLookupElement to consider next tab on template lookup element insert --- .../impl/TemplateExpressionLookupElement.java | 3 +- .../template/impl/TemplateState.java | 28 +++++++++++++++-- .../template/macro/BaseCompleteMacro.java | 31 +++---------------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateExpressionLookupElement.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateExpressionLookupElement.java index ccf774c3c18c..2bdf365d30a7 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateExpressionLookupElement.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateExpressionLookupElement.java @@ -27,7 +27,6 @@ import com.intellij.openapi.application.Result; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorModificationUtil; -import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiDocumentManager; @@ -72,7 +71,7 @@ class TemplateExpressionLookupElement extends LookupElementDecorator 0) { + int caret = myEditor.getCaretModel().getOffset(); + if (caret == range.getEndOffset()) { + nextTab(); + } + else if (caret > range.getEndOffset()) { + gotoEnd(true); + } + } + } + private void lockSegmentAtTheSameOffsetIfAny() { mySegments.lockSegmentAtTheSameOffsetIfAny(getCurrentSegmentNumber()); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/macro/BaseCompleteMacro.java b/platform/lang-impl/src/com/intellij/codeInsight/template/macro/BaseCompleteMacro.java index 033f779ac37d..08d386a1f20a 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/macro/BaseCompleteMacro.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/macro/BaseCompleteMacro.java @@ -27,9 +27,7 @@ import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiUtilBase; import org.jetbrains.annotations.NonNls; @@ -97,22 +95,6 @@ public abstract class BaseCompleteMacro extends Macro { ApplicationManager.getApplication().invokeLater(runnable); } - private static void considerNextTab(Editor editor) { - TemplateState templateState = TemplateManagerImpl.getTemplateState(editor); - if (templateState != null) { - TextRange range = templateState.getCurrentVariableRange(); - if (range != null && range.getLength() > 0) { - int caret = editor.getCaretModel().getOffset(); - if (caret == range.getEndOffset()) { - templateState.nextTab(); - } - else if (caret > range.getEndOffset()) { - templateState.gotoEnd(true); - } - } - } - } - protected abstract void invokeCompletionHandler(Project project, Editor editor); private static class MyLookupListener extends LookupAdapter { @@ -134,23 +116,20 @@ public abstract class BaseCompleteMacro extends Macro { return; } - for(TemplateCompletionProcessor processor: Extensions.getExtensions(TemplateCompletionProcessor.EP_NAME)) { - if (!processor.nextTabOnItemSelected(myContext, item)) { - return; - } - } - final Project project = myContext.getProject(); if (project == null) { return; } - + Runnable runnable = () -> new WriteCommandAction(project) { @Override protected void run(@NotNull com.intellij.openapi.application.Result result) throws Throwable { Editor editor = myContext.getEditor(); if (editor != null) { - considerNextTab(editor); + TemplateState templateState = TemplateManagerImpl.getTemplateState(editor); + if (templateState != null) { + templateState.considerNextTabOnLookupItemSelected(item); + } } } }.execute();