diff --git a/idea/src/org/jetbrains/jet/plugin/editor/KotlinTypedHandler.java b/idea/src/org/jetbrains/jet/plugin/editor/KotlinTypedHandler.java index d17f8eea95a..d812c8b1d56 100644 --- a/idea/src/org/jetbrains/jet/plugin/editor/KotlinTypedHandler.java +++ b/idea/src/org/jetbrains/jet/plugin/editor/KotlinTypedHandler.java @@ -115,6 +115,10 @@ public class KotlinTypedHandler extends TypedHandlerDelegate { case '.': autoPopupMemberLookup(project, editor); return Result.CONTINUE; + + case '@': + autoPopupLabelLookup(project, editor); + return Result.CONTINUE; } return Result.CONTINUE; @@ -135,6 +139,30 @@ public class KotlinTypedHandler extends TypedHandlerDelegate { }); } + private static void autoPopupLabelLookup(Project project, final Editor editor) { + AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, new Condition() { + @Override + public boolean value(PsiFile file) { + int offset = editor.getCaretModel().getOffset(); + + CharSequence chars = editor.getDocument().getCharsSequence(); + if (!endsWith(chars, offset, "this@") + && !endsWith(chars, offset, "return@") + && !endsWith(chars, offset, "break@") + && !endsWith(chars, offset, "continue@")) return false; + + PsiElement lastElement = file.findElementAt(offset - 1); + if (lastElement == null) return false; + + return lastElement.getNode().getElementType() == JetTokens.LABEL_IDENTIFIER; + } + }); + } + + private static boolean endsWith(CharSequence chars, int offset, String text) { + return chars.subSequence(offset - text.length(), offset).toString().equals(text); + } + @Override public Result charTyped(char c, Project project, @NotNull Editor editor, @NotNull PsiFile file) { if (!(file instanceof JetFile)) {