|
3 | 3 | import java.io.File; |
4 | 4 | import java.io.IOException; |
5 | 5 | import java.nio.file.Path; |
| 6 | +import java.util.ArrayList; |
| 7 | +import java.util.Collections; |
6 | 8 | import java.util.List; |
7 | 9 | import java.util.Objects; |
8 | 10 | import java.util.Optional; |
@@ -289,14 +291,32 @@ public void cut() { |
289 | 291 | } |
290 | 292 |
|
291 | 293 | private void scrollToRank(int delta) { |
292 | | - int currentRank = getSelectionModel().getSelectedItem().searchRankProperty().get(); |
293 | | - getItems().stream() |
294 | | - .filter(item -> item.searchRankProperty().get() == currentRank + delta) |
295 | | - .findFirst() |
296 | | - .ifPresent(item -> { |
297 | | - this.scrollTo(item); |
298 | | - this.clearAndSelect(item.getEntry()); |
299 | | - }); |
| 294 | + BibEntryTableViewModel selectedEntry = getSelectionModel().getSelectedItem(); |
| 295 | + if (selectedEntry == null) { |
| 296 | + return; |
| 297 | + } |
| 298 | + |
| 299 | + List<BibEntryTableViewModel> firstEntryOfEachRank = new ArrayList<>(Collections.nCopies(5, null)); |
| 300 | + for (BibEntryTableViewModel entry : getItems()) { |
| 301 | + int rank = entry.searchRankProperty().get(); |
| 302 | + if (firstEntryOfEachRank.get(rank) == null) { |
| 303 | + firstEntryOfEachRank.set(rank, entry); |
| 304 | + } |
| 305 | + if (rank == 4) { |
| 306 | + break; |
| 307 | + } |
| 308 | + } |
| 309 | + |
| 310 | + int targetRank = (selectedEntry.searchRankProperty().get()); |
| 311 | + while (true) { |
| 312 | + targetRank = Math.floorMod(targetRank + delta, 5); |
| 313 | + BibEntryTableViewModel entry = firstEntryOfEachRank.get(targetRank); |
| 314 | + if (entry != null) { |
| 315 | + scrollTo(entry); |
| 316 | + clearAndSelect(entry.getEntry()); |
| 317 | + return; |
| 318 | + } |
| 319 | + } |
300 | 320 | } |
301 | 321 |
|
302 | 322 | private void setupKeyBindings(KeyBindingRepository keyBindings) { |
|
0 commit comments