void (@NotNull AnActionEvent e) { ListSelectionModel sm = myTable.getSelectionModel(); String query = mySearch.getEnteredPrefix(); if (query == null) return; IntList filtered = mySearch.findAllFilteredRows(query); if (filtered.isEmpty()) { return; } boolean alreadySelected = Arrays.equals(filtered.toIntArray(), myTable.getSelectedRows()); if (alreadySelected) { int anchor = sm.getAnchorSelectionIndex(); sm.setSelectionInterval(anchor, anchor); sm.setAnchorSelectionIndex(anchor); mySearch.findAndSelectElement(query); } else { int anchor = -1; Object currentElement = mySearch.findElement(query); if (currentElement instanceof Integer) { int index = (Integer)currentElement; anchor = index / myTable.getColumnCount(); } if (anchor == -1) { anchor = filtered.getInt(0); } sm.clearSelection(); for (int i = 0; i < filtered.size(); i++) { int value = filtered.getInt(i); sm.addSelectionInterval(value, value); } sm.setAnchorSelectionIndex(anchor); } }