From 856c0c851059a32f9b83dcb5b7a3c7c8f33cfced Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 6 Aug 2012 13:35:58 +0200 Subject: [PATCH] another attempt for IDEA-89059 Selected item is scrolled off the bottom of the code completion popup --- .../codeInsight/lookup/impl/LookupImpl.java | 7 ++----- .../src/com/intellij/ui/ListScrollingUtil.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) 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 c3062942825c..458abf96a8c6 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 @@ -477,16 +477,13 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable updateListHeight(listModel); myList.setSelectedIndex(toSelect); - if (onExplicitAction && myShown) { - myList.ensureIndexIsVisible(toSelect); - } return !oldModel.equals(items); } } private boolean isSelectionVisible() { - return myList.getFirstVisibleIndex() <= myList.getSelectedIndex() && myList.getSelectedIndex() <= myList.getLastVisibleIndex(); + return ListScrollingUtil.isIndexFullyVisible(myList, myList.getSelectedIndex()); } private boolean checkReused() { @@ -1286,7 +1283,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable } HintManagerImpl.updateLocation(this, myEditor, rectangle.getLocation()); - if (reused || selectionVisible) { + if (reused || selectionVisible || onExplicitAction) { ensureSelectionVisible(); } } diff --git a/platform/platform-api/src/com/intellij/ui/ListScrollingUtil.java b/platform/platform-api/src/com/intellij/ui/ListScrollingUtil.java index f9613558d672..3b9576ab0b5b 100644 --- a/platform/platform-api/src/com/intellij/ui/ListScrollingUtil.java +++ b/platform/platform-api/src/com/intellij/ui/ListScrollingUtil.java @@ -176,6 +176,20 @@ public class ListScrollingUtil { } } + public static boolean isIndexFullyVisible(JList list, int index) { + int first = list.getFirstVisibleIndex(); + int last = list.getLastVisibleIndex(); + + if (index < 0 || first < 0 || last < 0 || index < first || index > last) { + return false; + } + if (index > first && index < last) { + return true; + } + + return list.getVisibleRect().contains(list.getCellBounds(index, index)); + } + private static int getVisibleRowCount(JList list) { return list.getLastVisibleIndex() - list.getFirstVisibleIndex() + 1; }