treat backspace/delete on interval border as outside template (IDEA-151493)

This commit is contained in:
Anna.Kozlova
2016-10-14 18:21:22 +02:00
parent b7ee8a55ff
commit 842afe69f1
2 changed files with 32 additions and 5 deletions
@@ -32,6 +32,7 @@ import com.intellij.openapi.util.text.StringUtil
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
import com.intellij.psi.codeStyle.CommonCodeStyleSettings
import com.intellij.testFramework.LightPlatformCodeInsightTestCase
import com.intellij.testFramework.fixtures.CodeInsightTestUtil
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import com.intellij.util.containers.ContainerUtil
@@ -1235,6 +1236,25 @@ class Foo {{
"""
}
void "test delete at the last template position"() {
myFixture.configureByText 'a.java', """
class Foo {{
<caret>
}}
"""
myFixture.type 'iter\t'
LightPlatformCodeInsightTestCase.delete(myFixture.editor, myFixture.project)
myFixture.checkResult """
class Foo {{
for (Object o : <caret> {
}
}}
"""
}
void "test multicaret expanding with space"() {
myFixture.configureByText "a.java", """\
class Foo {
@@ -22,8 +22,10 @@ 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.idea.ActionsBundle;
import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.CommandAdapter;
import com.intellij.openapi.command.CommandEvent;
@@ -122,7 +124,7 @@ public class TemplateState implements Disposable {
myLookupListener = new LookupAdapter() {
@Override
public void itemSelected(LookupEvent event) {
if (isCaretOutsideCurrentSegment()) {
if (isCaretOutsideCurrentSegment(null)) {
if (isCaretInsideNextVariable()) {
nextTab();
}
@@ -148,7 +150,7 @@ public class TemplateState implements Disposable {
@Override
public void commandStarted(CommandEvent event) {
myDocumentChangesTerminateTemplate = isCaretOutsideCurrentSegment();
myDocumentChangesTerminateTemplate = isCaretOutsideCurrentSegment(event.getCommandName());
started = true;
}
@@ -199,10 +201,15 @@ public class TemplateState implements Disposable {
return false;
}
private boolean isCaretOutsideCurrentSegment() {
private boolean isCaretOutsideCurrentSegment(String commandName) {
if (myEditor != null && myCurrentSegmentNumber >= 0) {
final int offset = myEditor.getCaretModel().getOffset();
return offset < mySegments.getSegmentStart(myCurrentSegmentNumber) || offset > mySegments.getSegmentEnd(myCurrentSegmentNumber);
final int segmentStart = mySegments.getSegmentStart(myCurrentSegmentNumber);
if (offset < segmentStart || offset == segmentStart && ActionsBundle.actionText(IdeActions.ACTION_EDITOR_BACKSPACE).equals(commandName)) return true;
final int segmentEnd = mySegments.getSegmentEnd(myCurrentSegmentNumber);
if (offset > segmentEnd || offset == segmentEnd && ActionsBundle.actionText(IdeActions.ACTION_EDITOR_DELETE).equals(commandName)) return true;
}
return false;
}
@@ -233,7 +240,7 @@ public class TemplateState implements Disposable {
}
public boolean isToProcessTab() {
if (isCaretOutsideCurrentSegment()) {
if (isCaretOutsideCurrentSegment(null)) {
return false;
}
if (ourLookupShown) {