mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Do not move caret to the $END$ marker on cancelling template (IDEA-111564, WEB-13513)
This commit is contained in:
@@ -23,6 +23,7 @@ import com.intellij.codeInsight.lookup.impl.LookupImpl
|
||||
import com.intellij.codeInsight.lookup.impl.LookupManagerImpl
|
||||
import com.intellij.codeInsight.template.impl.*
|
||||
import com.intellij.codeInsight.template.macro.*
|
||||
import com.intellij.openapi.actionSystem.IdeActions
|
||||
import com.intellij.openapi.command.WriteCommandAction
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.impl.DocumentImpl
|
||||
@@ -956,6 +957,24 @@ class Foo {
|
||||
return calculateResult(params, context)
|
||||
}
|
||||
}
|
||||
|
||||
public void "test escape shouldn't move caret to the end marker"() {
|
||||
myFixture.configureByText 'a.java', """
|
||||
class Foo {{
|
||||
itar<caret>
|
||||
}}
|
||||
"""
|
||||
myFixture.type '\ta'
|
||||
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_ESCAPE)
|
||||
myFixture.checkResult """
|
||||
class Foo {{
|
||||
for (int a<caret> = 0; a < array.length; a++) {
|
||||
= array[a];
|
||||
|
||||
}
|
||||
}}
|
||||
"""
|
||||
}
|
||||
|
||||
public void "test add new line on enter outside editing variable"() {
|
||||
myFixture.configureByText 'a.java', """
|
||||
|
||||
@@ -146,14 +146,14 @@ public class TemplateState implements Disposable {
|
||||
@Override
|
||||
public void caretAdded(CaretEvent e) {
|
||||
if (isMultiCaretMode()) {
|
||||
finishTemplateEditing(false);
|
||||
finishTemplateEditing();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void caretRemoved(CaretEvent e) {
|
||||
if (isMultiCaretMode()) {
|
||||
finishTemplateEditing(false);
|
||||
finishTemplateEditing();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -401,7 +401,7 @@ public class TemplateState implements Disposable {
|
||||
}
|
||||
|
||||
if (nextVariableNumber == -1) {
|
||||
finishTemplateEditing(false);
|
||||
finishTemplateEditing();
|
||||
}
|
||||
else {
|
||||
setCurrentVariableNumber(nextVariableNumber);
|
||||
@@ -410,7 +410,7 @@ public class TemplateState implements Disposable {
|
||||
focusCurrentExpression();
|
||||
currentVariableChanged(-1);
|
||||
if (isMultiCaretMode()) {
|
||||
finishTemplateEditing(false);
|
||||
finishTemplateEditing();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -668,7 +668,7 @@ public class TemplateState implements Disposable {
|
||||
final TextResult value = getVariableValue(variableName);
|
||||
if (value != null && !value.getText().isEmpty()) {
|
||||
if (!myProcessor.process(variableName, value.getText())) {
|
||||
finishTemplateEditing(false); // nextTab(); ?
|
||||
finishTemplateEditing(); // nextTab(); ?
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -856,7 +856,7 @@ public class TemplateState implements Disposable {
|
||||
reformat(null);
|
||||
}
|
||||
});
|
||||
finishTemplateEditing(false);
|
||||
finishTemplateEditing();
|
||||
return;
|
||||
}
|
||||
focusCurrentHighlighter(false);
|
||||
@@ -931,36 +931,30 @@ public class TemplateState implements Disposable {
|
||||
|
||||
public void gotoEnd(boolean brokenOff) {
|
||||
if (myTemplate == null) return;
|
||||
LookupManager.getInstance(myProject).hideActiveLookup();
|
||||
calcResults(false);
|
||||
if (!brokenOff) {
|
||||
doReformat(null);
|
||||
}
|
||||
finishTemplateEditing(brokenOff);
|
||||
setFinalEditorState(brokenOff);
|
||||
cleanupTemplateState(brokenOff);
|
||||
}
|
||||
|
||||
public void gotoEnd() {
|
||||
gotoEnd(true);
|
||||
}
|
||||
|
||||
public void cancelTemplate() {
|
||||
private void finishTemplateEditing() {
|
||||
if (myTemplate == null) return;
|
||||
|
||||
LookupManager.getInstance(myProject).hideActiveLookup();
|
||||
|
||||
cleanupTemplateState(true);
|
||||
setFinalEditorState(false);
|
||||
cleanupTemplateState(false);
|
||||
}
|
||||
|
||||
private void finishTemplateEditing(boolean brokenOff) {
|
||||
if (myTemplate == null) return;
|
||||
|
||||
|
||||
LookupManager.getInstance(myProject).hideActiveLookup();
|
||||
|
||||
setFinalEditorState();
|
||||
cleanupTemplateState(brokenOff);
|
||||
}
|
||||
|
||||
private void setFinalEditorState() {
|
||||
private void setFinalEditorState(boolean brokenOff) {
|
||||
myEditor.getSelectionModel().removeSelection();
|
||||
if (brokenOff && !((TemplateManagerImpl)TemplateManager.getInstance(myProject)).shouldSkipInTests()) return;
|
||||
|
||||
int selectionSegment = myTemplate.getVariableSegmentNumber(TemplateImpl.SELECTION);
|
||||
int endSegmentNumber = selectionSegment >= 0 && getSelectionBeforeTemplate() == null ? selectionSegment : myTemplate.getEndSegmentNumber();
|
||||
int offset = -1;
|
||||
@@ -981,8 +975,7 @@ public class TemplateState implements Disposable {
|
||||
myEditor.getCaretModel().moveToOffset(offset);
|
||||
myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
}
|
||||
|
||||
myEditor.getSelectionModel().removeSelection();
|
||||
|
||||
int selStart = myTemplate.getSelectionStartSegmentNumber();
|
||||
int selEnd = myTemplate.getSelectionEndSegmentNumber();
|
||||
if (selStart >= 0 && selEnd >= 0) {
|
||||
|
||||
+1
-1
@@ -115,7 +115,7 @@ public abstract class BaseCompleteMacro extends Macro {
|
||||
templateState.nextTab();
|
||||
}
|
||||
else if (caret > range.getEndOffset()) {
|
||||
templateState.cancelTemplate();
|
||||
templateState.gotoEnd(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -157,13 +157,13 @@ public class XmlTagInsertHandler implements InsertHandler<LookupElement> {
|
||||
public void templateFinished(final Template template, boolean brokenOff) {
|
||||
final int offset = editor.getCaretModel().getOffset();
|
||||
|
||||
if (chooseAttributeName && offset >= 3) {
|
||||
char c = editor.getDocument().getCharsSequence().charAt(offset - 3);
|
||||
if (chooseAttributeName && offset > 0) {
|
||||
char c = editor.getDocument().getCharsSequence().charAt(offset - 1);
|
||||
if (c == '/' || (c == ' ' && brokenOff)) {
|
||||
new WriteCommandAction.Simple(project) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
editor.getDocument().replaceString(offset - 2, offset + 1, ">");
|
||||
editor.getDocument().replaceString(offset, offset + 3, ">");
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user