mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-158139 Make TemplateExpressionLookupElement to consider next tab on template lookup element insert
This commit is contained in:
+1
-2
@@ -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<LookupEleme
|
||||
|
||||
if (handleCompletionChar(context) && !myState.isFinished()) {
|
||||
myState.calcResults(true);
|
||||
myState.nextTab();
|
||||
myState.considerNextTabOnLookupItemSelected(getDelegate());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.CodeInsightSettings;
|
||||
import com.intellij.codeInsight.lookup.*;
|
||||
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
||||
import com.intellij.codeInsight.template.*;
|
||||
import com.intellij.codeInsight.template.macro.TemplateCompletionProcessor;
|
||||
import com.intellij.diagnostic.AttachmentFactory;
|
||||
import com.intellij.lang.injection.InjectedLanguageManager;
|
||||
import com.intellij.openapi.Disposable;
|
||||
@@ -122,7 +123,7 @@ public class TemplateState implements Disposable {
|
||||
@Override
|
||||
public void itemSelected(LookupEvent event) {
|
||||
if (isCaretOutsideCurrentSegment()) {
|
||||
gotoEnd(true);
|
||||
gotoEnd(true);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -205,7 +206,7 @@ public class TemplateState implements Disposable {
|
||||
}
|
||||
myLookupListener = null;
|
||||
}
|
||||
|
||||
|
||||
myEditorDocumentListener = null;
|
||||
myCommandListener = null;
|
||||
myCaretListener = null;
|
||||
@@ -858,7 +859,7 @@ public class TemplateState implements Disposable {
|
||||
private void replaceString(String newValue, int start, int end, int segmentNumber) {
|
||||
TextRange range = TextRange.create(start, end);
|
||||
if (!TextRange.from(0, myDocument.getCharsSequence().length()).contains(range)) {
|
||||
LOG.error("Diagnostic for EA-54980. Can't extract " + range + " range. " + presentTemplate(myTemplate),
|
||||
LOG.error("Diagnostic for EA-54980. Can't extract " + range + " range. " + presentTemplate(myTemplate),
|
||||
AttachmentFactory.createAttachment(myDocument));
|
||||
}
|
||||
String oldText = range.subSequence(myDocument.getCharsSequence()).toString();
|
||||
@@ -922,6 +923,27 @@ public class TemplateState implements Disposable {
|
||||
currentVariableChanged(oldVar);
|
||||
}
|
||||
|
||||
public void considerNextTabOnLookupItemSelected(LookupElement item) {
|
||||
if (item != null) {
|
||||
ExpressionContext context = getCurrentExpressionContext();
|
||||
for (TemplateCompletionProcessor processor : Extensions.getExtensions(TemplateCompletionProcessor.EP_NAME)) {
|
||||
if (!processor.nextTabOnItemSelected(context, item)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
TextRange range = getCurrentVariableRange();
|
||||
if (range != null && range.getLength() > 0) {
|
||||
int caret = myEditor.getCaretModel().getOffset();
|
||||
if (caret == range.getEndOffset()) {
|
||||
nextTab();
|
||||
}
|
||||
else if (caret > range.getEndOffset()) {
|
||||
gotoEnd(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void lockSegmentAtTheSameOffsetIfAny() {
|
||||
mySegments.lockSegmentAtTheSameOffsetIfAny(getCurrentSegmentNumber());
|
||||
}
|
||||
|
||||
+5
-26
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user