diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java index 00cf65981960..7017fa621fb9 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java @@ -120,7 +120,8 @@ public class CodeCompletionHandlerBase { CompletionAssertions.checkEditorValid(editor); - if (editor.isViewer() || editor.getDocument().getOffsetGuard(editor.getCaretModel().getOffset()) != null) { + int offset = editor.getCaretModel().getOffset(); + if (editor.isViewer() || editor.getDocument().getRangeGuard(offset, offset) != null) { editor.getDocument().fireReadOnlyModificationAttempt(); CodeInsightUtilBase.showReadOnlyViewWarning(editor); return; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/actions/HippieWordCompletionHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/actions/HippieWordCompletionHandler.java index 4f502326e482..645e791a753b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/actions/HippieWordCompletionHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/actions/HippieWordCompletionHandler.java @@ -55,7 +55,8 @@ public class HippieWordCompletionHandler implements CodeInsightActionHandler { public void invoke(@NotNull Project project, @NotNull final Editor editor, @NotNull PsiFile file) { if (!FileModificationService.getInstance().prepareFileForWrite(file)) return; - if (editor.isViewer() || editor.getDocument().getOffsetGuard(editor.getCaretModel().getOffset()) != null) { + int offset = editor.getCaretModel().getOffset(); + if (editor.isViewer() || editor.getDocument().getRangeGuard(offset, offset) != null) { editor.getDocument().fireReadOnlyModificationAttempt(); CodeInsightUtilBase.showReadOnlyViewWarning(editor); return; diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/GuardBlockTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/GuardBlockTest.java index 01b205322c72..d441c61209ce 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/GuardBlockTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/GuardBlockTest.java @@ -78,13 +78,24 @@ public class GuardBlockTest extends LightPlatformCodeInsightFixtureTestCase { public void testNoCompletion() throws Exception { String text = "abc abd a abx"; myFixture.configureByText("x.txt", text); - createGuard(0, myFixture.getFile().getTextLength()); + int offset = myFixture.getEditor().getCaretModel().getOffset(); + createGuard(offset - 1, myFixture.getFile().getTextLength()).setGreedyToRight(true); assertNull(myFixture.completeBasic()); myFixture.checkResult(text); + //no hippie completion myFixture.performEditorAction(IdeActions.ACTION_HIPPIE_BACKWARD_COMPLETION); assertNull(LookupManager.getInstance(getProject()).getActiveLookup()); myFixture.checkResult(text); + + //no completion at the file end + myFixture.getEditor().getCaretModel().moveToOffset(myFixture.getFile().getTextLength()); + assertNull(myFixture.completeBasic()); + myFixture.checkResult("abc abd a abx"); + + //completion at the beginning of the guard fragment + myFixture.getEditor().getCaretModel().moveToOffset(offset - 1); + assertNotNull(myFixture.completeBasic()); } }