Skip to content

Commit 7ad0aad

Browse files
Maximilian WittmerMaximilian Wittmer
authored andcommitted
SearchHistoryMenu: improve scrolling through selection with arrow keys
Scrolling through the selection of the Search History now correctly starts at the first item and cycles through the boundaries (ie. scrolling down from the last item returns correctly to the first item of the list) fixes #2139
1 parent 06f82a4 commit 7ad0aad

File tree

1 file changed

+29
-0
lines changed
  • bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay

1 file changed

+29
-0
lines changed

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/SearchHistoryMenu.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public void shellDeactivated(ShellEvent e) {
5454
private int width;
5555
private Table table;
5656
private TableColumn column;
57+
private int selectedIndexInTable = -1;
5758

5859
public SearchHistoryMenu(Shell parent, HistoryStore history, Consumer<String> historyEntrySelectedCallback) {
5960
super(parent);
@@ -92,7 +93,35 @@ public Control createContents(Composite parent) {
9293
return table;
9394
}
9495

96+
private void moveSelectionInTable(int indexShift) {
97+
selectedIndexInTable += indexShift;
98+
if (selectedIndexInTable < 0) {
99+
selectedIndexInTable = table.getItemCount() - 1;
100+
} else if (selectedIndexInTable > table.getItemCount() - 1) {
101+
selectedIndexInTable = 0;
102+
}
103+
table.setSelection(selectedIndexInTable);
104+
historyEntrySelectedCallback.accept(table.getSelection()[0].getText());
105+
}
106+
95107
private void attachTableListeners() {
108+
table.addListener(SWT.MouseMove, event -> {
109+
Point point = new Point(event.x, event.y);
110+
TableItem item = table.getItem(point);
111+
if (item != null) {
112+
table.setSelection(item);
113+
selectedIndexInTable = table.getSelectionIndex();
114+
}
115+
});
116+
table.addKeyListener(KeyListener.keyPressedAdapter(e -> {
117+
if (e.keyCode == SWT.ARROW_DOWN) {
118+
moveSelectionInTable(1);
119+
e.doit = false;
120+
} else if (e.keyCode == SWT.ARROW_UP) {
121+
moveSelectionInTable(-1);
122+
e.doit = false;
123+
}
124+
}));
96125
table.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
97126
TableItem[] selection = table.getSelection();
98127
if (selection.length == 0) {

0 commit comments

Comments
 (0)