diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/simple/ParenthesesTailType.java b/java/java-impl/src/com/intellij/codeInsight/completion/simple/ParenthesesTailType.java index 2436ce146de6..0ae4b0824d18 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/simple/ParenthesesTailType.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/simple/ParenthesesTailType.java @@ -1,22 +1,9 @@ -/* - * Copyright 2000-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.completion.simple; import com.intellij.codeInsight.TailType; +import com.intellij.codeInsight.editorActions.TabOutScopesTracker; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.psi.codeStyle.CommonCodeStyleSettings; @@ -50,6 +37,7 @@ public abstract class ParenthesesTailType extends TailType { } else { tailOffset = insertChar(editor, tailOffset, ')'); moveCaret(editor, tailOffset, -1); + TabOutScopesTracker.getInstance().registerEmptyScopeAtCaret(editor); } return tailOffset; } diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/EditorTabOutTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/EditorTabOutTest.java index 8b6193ef0cbc..ef37321c9f8b 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/EditorTabOutTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/EditorTabOutTest.java @@ -65,6 +65,14 @@ public class EditorTabOutTest extends AbstractParameterInfoTestCase { checkResult("class C { int[] ar = new int[123] }"); } + public void testWhile() { + configureJava("class C { void m() { whil } }"); + complete(); + type("true"); + tabOut(); + checkResult("class C { void m() { while (true)} }"); + } + private void tabOut() { myFixture.performEditorAction(IdeActions.ACTION_BRACE_OR_QUOTE_OUT); } diff --git a/platform/lang-api/src/com/intellij/codeInsight/completion/util/ParenthesesInsertHandler.java b/platform/lang-api/src/com/intellij/codeInsight/completion/util/ParenthesesInsertHandler.java index 40d956c3af9a..7f781ba056c8 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/completion/util/ParenthesesInsertHandler.java +++ b/platform/lang-api/src/com/intellij/codeInsight/completion/util/ParenthesesInsertHandler.java @@ -160,7 +160,7 @@ public abstract class ParenthesesInsertHandler implemen editor.getCaretModel().moveToOffset(context.getTailOffset()); } else if (!mySpaceBeforeParentheses) { - TabOutScopesTracker.getInstance().registerEmptyScope(editor, editor.getCaretModel().getOffset()); + TabOutScopesTracker.getInstance().registerEmptyScopeAtCaret(editor); } } diff --git a/platform/lang-api/src/com/intellij/codeInsight/editorActions/TabOutScopesTracker.java b/platform/lang-api/src/com/intellij/codeInsight/editorActions/TabOutScopesTracker.java index 37ec18fd3735..814a69a3936a 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/editorActions/TabOutScopesTracker.java +++ b/platform/lang-api/src/com/intellij/codeInsight/editorActions/TabOutScopesTracker.java @@ -17,6 +17,14 @@ public interface TabOutScopesTracker { return ServiceManager.getService(TabOutScopesTracker.class); } + /** + * Registers a new scope (empty at the time of call) at caret offset. Caret is supposed to be located between just inserted pair + * of quotes/brackets. + */ + default void registerEmptyScopeAtCaret(@NotNull Editor editor) { + registerEmptyScope(editor, editor.getCaretModel().getOffset()); + } + /** * Registers a new scope (empty at the time of call) at the given offset. Provided offset is supposed to point at the location between * just inserted pair of quotes/brackets.