mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
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:
@@ -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>'
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user