mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Sort search results in Find in Path preview table (IDEA-173424)
GitOrigin-RevId: ece09b47a4f73010e6c1b57084d132b4700ca81a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
17688de424
commit
7bd962bd8a
@@ -83,6 +83,7 @@ import java.awt.event.*;
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@@ -1089,10 +1090,40 @@ public class FindPopupPanel extends JBPanel implements FindUI {
|
||||
final int hash = System.identityHashCode(myResultsPreviewSearchProgress);
|
||||
|
||||
final DefaultTableModel model = new DefaultTableModel() {
|
||||
private final Comparator<Vector<UsageInfo2UsageAdapter>> COMPARATOR = (v1, v2) -> {
|
||||
UsageInfo2UsageAdapter u1 = v1.get(0);
|
||||
UsageInfo2UsageAdapter u2 = v2.get(0);
|
||||
int c = u1.getFile().getPath().compareTo(u2.getFile().getPath());
|
||||
if (c != 0) return c;
|
||||
c = Integer.compare(u1.getLine(), u2.getLine());
|
||||
if (c != 0) return c;
|
||||
return Integer.compare(u1.getUsageInfo().getNavigationOffset(), u2.getUsageInfo().getNavigationOffset());
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"UseOfObsoleteCollectionType", "unchecked"})
|
||||
@Override
|
||||
//Inserts search results in sorted order
|
||||
public void addRow(Object[] rowData) {
|
||||
final Vector<UsageInfo2UsageAdapter> v = convertToVector(rowData);
|
||||
final int p = Collections.binarySearch(dataVector, v, COMPARATOR);
|
||||
assert p < 0 : "duplicate result found";
|
||||
|
||||
int row = -(p + 1);
|
||||
boolean fixSelection = row == myResultsPreviewTable.getSelectedRow() && myResultsPreviewTable.getSelectedRowCount() == 1;
|
||||
insertRow(row, v);
|
||||
|
||||
if (fixSelection) {
|
||||
// Inserting a row at the selection position grows the selection by 1.
|
||||
// Prevent that growing and set the selection back to the row only.
|
||||
if (row != 0) row++; // non-default selection, keep the item
|
||||
myResultsPreviewTable.setRowSelectionInterval(row, row);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
model.addColumn("Usages");
|
||||
|
||||
Reference in New Issue
Block a user