mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-118389 Forbid completion inside guard blocks; honor greediness
This commit is contained in:
+2
-1
@@ -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;
|
||||
|
||||
+2
-1
@@ -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;
|
||||
|
||||
+12
-1
@@ -78,13 +78,24 @@ public class GuardBlockTest extends LightPlatformCodeInsightFixtureTestCase {
|
||||
public void testNoCompletion() throws Exception {
|
||||
String text = "abc abd a<caret> 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<caret>");
|
||||
|
||||
//completion at the beginning of the guard fragment
|
||||
myFixture.getEditor().getCaretModel().moveToOffset(offset - 1);
|
||||
assertNotNull(myFixture.completeBasic());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user