mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-110404 Allow surround-style live template expansion to work
This commit is contained in:
@@ -616,4 +616,10 @@ class Foo {
|
||||
assert myFixture.lookupElementStrings == ['value', 'value1']
|
||||
}
|
||||
|
||||
public void "test invoke surround template by tab"() {
|
||||
myFixture.configureByText "a.txt", "B<caret>"
|
||||
myFixture.type('\t')
|
||||
myFixture.checkResult("{<caret>}")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -100,7 +100,7 @@ public class LiveTemplateCompletionContributor extends CompletionContributor {
|
||||
|
||||
final ArrayList<TemplateImpl> result = ContainerUtil.newArrayList();
|
||||
for (final TemplateImpl template : TemplateSettings.getInstance().getTemplates()) {
|
||||
if (!template.isDeactivated() && !template.isSelectionTemplate() && TemplateManagerImpl.isApplicable(template, contextTypes)) {
|
||||
if (!template.isDeactivated() && TemplateManagerImpl.isApplicable(template, contextTypes)) {
|
||||
result.add(template);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -104,10 +104,10 @@ public class SurroundWithTemplateHandler implements CodeInsightActionHandler {
|
||||
return template.isApplicable(file, editor.getSelectionModel().getSelectionStart(), true);
|
||||
}
|
||||
|
||||
public static ArrayList<TemplateImpl> getApplicableTemplates(Editor editor, PsiFile file, boolean selection) {
|
||||
public static ArrayList<TemplateImpl> getApplicableTemplates(Editor editor, PsiFile file, boolean selectionOnly) {
|
||||
|
||||
int startOffset = editor.getCaretModel().getOffset();
|
||||
if (selection && editor.getSelectionModel().hasSelection()) {
|
||||
if (editor.getSelectionModel().hasSelection()) {
|
||||
startOffset = editor.getSelectionModel().getSelectionStart();
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ public class SurroundWithTemplateHandler implements CodeInsightActionHandler {
|
||||
ArrayList<TemplateImpl> list = new ArrayList<TemplateImpl>();
|
||||
for (TemplateImpl template : TemplateSettings.getInstance().getTemplates()) {
|
||||
if (!template.isDeactivated() &&
|
||||
template.isSelectionTemplate() == selection &&
|
||||
(!selectionOnly || template.isSelectionTemplate()) &&
|
||||
TemplateManagerImpl.isApplicable(file, startOffset, template)) {
|
||||
list.add(template);
|
||||
}
|
||||
|
||||
@@ -734,9 +734,6 @@ public class TemplateSettings implements PersistentStateComponent<Element>, Expo
|
||||
if (shortcutChar != null && getShortcutChar(template) != shortcutChar) {
|
||||
continue;
|
||||
}
|
||||
if (template.isSelectionTemplate()) {
|
||||
continue;
|
||||
}
|
||||
if (hasArgument && !template.hasArgument()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -846,6 +846,11 @@ public class TemplateState implements Disposable {
|
||||
else {
|
||||
if (!myTemplate.isSelectionTemplate() && !myTemplate.isInline()) { //do not move caret to the end of range for selection templates
|
||||
offset = myTemplateRange.getEndOffset();
|
||||
} else {
|
||||
int selectionSegment = myTemplate.getVariableSegmentNumber(TemplateImpl.SELECTION);
|
||||
if (selectionSegment >= 0 && mySegments.getSegmentStart(selectionSegment) == mySegments.getSegmentEnd(selectionSegment)) {
|
||||
offset = mySegments.getSegmentStart(selectionSegment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user