diff --git a/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java b/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java index 6ad6897e57b0..fcbc53849259 100644 --- a/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java +++ b/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java @@ -860,6 +860,9 @@ public class ShowUsagesAction extends AnAction implements PopupAction { window.setLocation(rectangle.getLocation()); } + if (!data.isEmpty()) { + TableScrollingUtil.ensureSelectionExists(table); + } table.setSize(dimension); //table.setPreferredSize(dimension); //table.setMaximumSize(dimension); diff --git a/platform/platform-api/src/com/intellij/ui/TableScrollingUtil.java b/platform/platform-api/src/com/intellij/ui/TableScrollingUtil.java index e3993f86206d..7b30f2223a39 100644 --- a/platform/platform-api/src/com/intellij/ui/TableScrollingUtil.java +++ b/platform/platform-api/src/com/intellij/ui/TableScrollingUtil.java @@ -21,6 +21,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CustomShortcutSet; import com.intellij.openapi.util.Pair; import org.intellij.lang.annotations.JdkConstants; +import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; @@ -62,9 +63,26 @@ public class TableScrollingUtil { } } + public static void ensureSelectionExists(@NotNull JTable list) { + int size = list.getModel().getRowCount(); + if (size == 0) { + list.clearSelection(); + return; + } + int selectedIndex = list.getSelectedRow(); + boolean reselect = false; + if (selectedIndex < 0 || selectedIndex >= size) { // fit index to [0, size-1] range + selectedIndex = 0; + reselect = true; + } + ensureIndexIsVisible(list, selectedIndex, 0); + if (reselect) { + list.getSelectionModel().setSelectionInterval(selectedIndex, selectedIndex); + } + } + private static Rectangle getCellBounds(JTable table, int top, int bottom) { - Rectangle cellBounds = table.getCellRect(top, 0, true).union(table.getCellRect(bottom,0,true)); - return cellBounds; + return table.getCellRect(top, 0, true).union(table.getCellRect(bottom,0,true)); } private static int getVisibleRowCount(JTable list) {