From 1135a571f9330ce90f1b53ef7f6a1ded18077be5 Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 28 Jan 2011 17:28:13 +0100 Subject: [PATCH] a test for up/down arrows in autopopup --- .../completion/JavaAutoPopupTest.groovy | 47 ++++++++++++++++++- .../codeInsight/lookup/impl/LookupImpl.java | 7 ++- .../impl/CodeInsightTestFixtureImpl.java | 6 +++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy index 7103efd2f6a8..685da3fd12c4 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy @@ -16,9 +16,10 @@ package com.intellij.codeInsight.completion import com.intellij.codeInsight.lookup.Lookup +import com.intellij.codeInsight.lookup.LookupManager import com.intellij.openapi.actionSystem.IdeActions import com.intellij.openapi.command.CommandProcessor -import com.intellij.codeInsight.lookup.LookupManager +import com.intellij.ide.ui.UISettings /** * @author peter @@ -388,4 +389,48 @@ class JavaAutoPopupTest extends CompletionAutoPopupTestCase { assert !lookup } + void testArrow(boolean up, boolean cycleScrolling, boolean lookupAbove, int index) { + myFixture.configureByText("a.java", """ + class A { + { ArrayIndexOutOfBoundsException } + } + """) + + type 'o' + assert lookup + assert !lookup.focused + assert lookup.items.size() == 2 + + UISettings.instance.CYCLE_SCROLLING = cycleScrolling + + try { + edt { myFixture.performEditorAction(up ? IdeActions.ACTION_EDITOR_MOVE_CARET_UP : IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN) } + if (lookup) { + assert lookup.focused + assert index >= 0 + assert lookup.items[index] == lookup.currentItem + edt { lookup.hide() } + } else { + assert index == -1 + } + type '\b' + } + finally { + UISettings.instance.CYCLE_SCROLLING = true + } + + } + + void testArrows(boolean cycleScrolling, boolean lookupAbove, int indexDown, indexUp) { + testArrow true, cycleScrolling, lookupAbove, indexUp + testArrow false, cycleScrolling, lookupAbove, indexDown + } + + public void testVerticalArrows() { + testArrows false, false, 0, -1 + testArrows false, true, 0, -1 + testArrows true, false, 0, 1 + testArrows true, true, 0, 1 + } + } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java index c81d3d1adc3d..7053e6e5e090 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupImpl.java @@ -517,7 +517,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { int shiftLow = layeredPane.getHeight() - (layeredPanePoint.y + dim.height); int shiftHigh = layeredPanePoint.y - dim.height; if (!isPositionedAboveCaret()) { - myPositionedAbove = shiftLow < 0 && shiftLow < shiftHigh ? Boolean.TRUE : Boolean.FALSE; + myPositionedAbove = shiftLow < 0 && shiftLow < shiftHigh; } if (isPositionedAboveCaret()) { layeredPanePoint.y -= dim.height + myEditor.getLineHeight(); @@ -927,6 +927,11 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable { return myEditor; } + @TestOnly + public void setPositionedAbove(boolean positionedAbove) { + myPositionedAbove = positionedAbove; + } + public boolean isPositionedAboveCaret(){ return myPositionedAbove != null && myPositionedAbove.booleanValue(); } diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index 80d323e47d63..f9159d1aed9c 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -67,6 +67,7 @@ import com.intellij.openapi.editor.markup.RangeHighlighter; import com.intellij.openapi.extensions.ExtensionPoint; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.extensions.ExtensionsArea; +import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.fileEditor.OpenFileDescriptor; import com.intellij.openapi.fileEditor.TextEditor; @@ -1143,6 +1144,11 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig final File tempFile = FileUtil.createTempFile(new File(getTempDirPath()), prefix, "." + StringUtil.getShortName(fileName), true); vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempFile); } + final Document document = FileDocumentManager.getInstance().getCachedDocument(vFile); + if (document != null) { + FileDocumentManager.getInstance().saveDocument(document); + } + VfsUtil.saveText(vFile, text); configureInner(vFile, SelectionAndCaretMarkupLoader.fromFile(vFile, getProject())); }