mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
Live templates: list template action should work in multi-carets mode (IDEA-182741)
GitOrigin-RevId: 7617b4d3c2bcc7bafef15ef0199eac08f6cb8491
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0585365e24
commit
8ccd4547f5
@@ -0,0 +1,6 @@
|
||||
class A {
|
||||
public static void main() {
|
||||
<caret>
|
||||
<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class A {
|
||||
public static void main() {
|
||||
si<caret>
|
||||
si<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class A {
|
||||
public static void main() {
|
||||
simple template text<caret>
|
||||
simple template text<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class A {
|
||||
public static void main() {
|
||||
simple template text<caret>
|
||||
simple template text<caret>
|
||||
}
|
||||
}
|
||||
@@ -97,6 +97,14 @@ public class ListTemplateActionTest extends LightJavaCodeInsightFixtureTestCase
|
||||
doTest("template.with.desc");
|
||||
}
|
||||
|
||||
public void testMulticaret() {
|
||||
doTest("simple");
|
||||
}
|
||||
|
||||
public void testMulticaretWithPrefix() {
|
||||
doTest("simple");
|
||||
}
|
||||
|
||||
private void doTest(@NotNull String lookupText) {
|
||||
myFixture.configureByFile(getTestName(false) + ".java");
|
||||
new ListTemplatesAction().actionPerformedImpl(myFixture.getProject(), myFixture.getEditor());
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
|
||||
package com.intellij.codeInsight.template.impl;
|
||||
|
||||
@@ -236,11 +236,26 @@ public class ListTemplatesHandler implements CodeInsightActionHandler {
|
||||
if (item instanceof LiveTemplateLookupElementImpl) {
|
||||
final TemplateImpl template = ((LiveTemplateLookupElementImpl)item).getTemplate();
|
||||
final String argument = myTemplate2Argument != null ? myTemplate2Argument.get(template) : null;
|
||||
WriteCommandAction.writeCommandAction(project).run(() -> ((TemplateManagerImpl)TemplateManager.getInstance(project)).startTemplateWithPrefix(lookup.getEditor(), template, null, argument));
|
||||
WriteCommandAction.writeCommandAction(project).run(() -> {
|
||||
Editor editor = lookup.getEditor();
|
||||
if (!editor.isDisposed()) {
|
||||
editor.getCaretModel().runForEachCaret(caret -> {
|
||||
((TemplateManagerImpl)TemplateManager.getInstance(project))
|
||||
.startTemplateWithPrefix(caret.getEditor(), template, null, argument);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (item instanceof CustomLiveTemplateLookupElement) {
|
||||
if (myFile != null) {
|
||||
WriteCommandAction.writeCommandAction(project).run(() -> ((CustomLiveTemplateLookupElement)item).expandTemplate(lookup.getEditor(), myFile));
|
||||
WriteCommandAction.writeCommandAction(project).run(() -> {
|
||||
Editor editor = lookup.getEditor();
|
||||
if (!editor.isDisposed()) {
|
||||
editor.getCaretModel().runForEachCaret(caret -> {
|
||||
((CustomLiveTemplateLookupElement)item).expandTemplate(lookup.getEditor(), myFile);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -260,7 +275,7 @@ public class ListTemplatesHandler implements CodeInsightActionHandler {
|
||||
result.addAll(items);
|
||||
ArrayList<LookupElement> list = new ArrayList<>(result);
|
||||
int selected = lookup.isSelectionTouched() ? list.indexOf(lookup.getCurrentItem()) : 0;
|
||||
return new Pair<>(list, selected >= 0 ? selected : 0);
|
||||
return new Pair<>(list, Math.max(selected, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user