make second home/end leave the live template fragment and work as usual

to make it easier to cut/copy stuff from the rest of the line
This commit is contained in:
peter
2016-09-16 08:07:02 +02:00
parent d4e5f5a2c4
commit ade087c842
2 changed files with 30 additions and 1 deletions
@@ -1478,4 +1478,28 @@ java.util.List<? extends Integer> list;
}
}}'''
}
void "test home end go outside template fragments if already on their bounds"() {
myFixture.configureByText 'a.txt', ' <caret> g'
TemplateManager manager = TemplateManager.getInstance(getProject())
Template template = manager.createTemplate("empty", "user", '$VAR$')
template.addVariable("VAR", "", '"foo"', true)
manager.startTemplate(myFixture.editor, template)
myFixture.checkResult ' <selection>foo<caret></selection> g'
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_LINE_START)
myFixture.checkResult ' <caret>foo g'
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_LINE_START)
myFixture.checkResult '<caret> foo g'
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT)
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_LINE_END)
myFixture.checkResult ' foo<caret> g'
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_MOVE_LINE_END)
myFixture.checkResult ' foo g<caret>'
}
}
@@ -56,7 +56,7 @@ public abstract class TemplateLineStartEndHandler extends EditorActionHandler {
if (templateState != null && !templateState.isFinished()) {
final TextRange range = templateState.getCurrentVariableRange();
final int caretOffset = editor.getCaretModel().getOffset();
if (range != null && range.containsOffset(caretOffset)) {
if (range != null && shouldStayInsideVariable(range, caretOffset)) {
int selectionOffset = editor.getSelectionModel().getLeadSelectionOffset();
int offsetToMove = myIsHomeHandler ? range.getStartOffset() : range.getEndOffset();
editor.getCaretModel().moveToOffset(offsetToMove);
@@ -72,4 +72,9 @@ public abstract class TemplateLineStartEndHandler extends EditorActionHandler {
}
myOriginalHandler.execute(editor, caret, dataContext);
}
private boolean shouldStayInsideVariable(TextRange varRange, int caretOffset) {
return varRange.containsOffset(caretOffset) &&
caretOffset != (myIsHomeHandler ? varRange.getStartOffset() : varRange.getEndOffset());
}
}