another attempt for IDEA-89059 Selected item is scrolled off the bottom of the code completion popup

This commit is contained in:
peter
2012-08-06 14:14:55 +02:00
parent d54300ab46
commit 856c0c8510
2 changed files with 16 additions and 5 deletions
@@ -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();
}
}
@@ -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;
}