|  | 
| 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; | 
| @@ -247,8 +249,9 @@ private void jumpToSearchKey(TableColumn<BibEntryTableViewModel, ?> sortedColumn | 
| 247 | 249 |                                     .startsWith(columnSearchTerm)) | 
| 248 | 250 |             .findFirst() | 
| 249 | 251 |             .ifPresent(item -> { | 
| 250 |  | -                this.scrollTo(item); | 
| 251 |  | -                this.clearAndSelect(item.getEntry()); | 
|  | 252 | +                getSelectionModel().clearSelection(); | 
|  | 253 | +                getSelectionModel().select(item); | 
|  | 254 | +                scrollTo(item); | 
| 252 | 255 |             }); | 
| 253 | 256 |     } | 
| 254 | 257 | 
 | 
| @@ -289,14 +292,33 @@ public void cut() { | 
| 289 | 292 |     } | 
| 290 | 293 | 
 | 
| 291 | 294 |     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 |  | -                  }); | 
|  | 295 | +        BibEntryTableViewModel selectedEntry = getSelectionModel().getSelectedItem(); | 
|  | 296 | +        if (selectedEntry == null) { | 
|  | 297 | +            return; | 
|  | 298 | +        } | 
|  | 299 | + | 
|  | 300 | +        List<BibEntryTableViewModel> firstEntryOfEachRank = new ArrayList<>(Collections.nCopies(5, null)); | 
|  | 301 | +        for (BibEntryTableViewModel entry : getItems()) { | 
|  | 302 | +            int rank = entry.searchRankProperty().get(); | 
|  | 303 | +            if (firstEntryOfEachRank.get(rank) == null) { | 
|  | 304 | +                firstEntryOfEachRank.set(rank, entry); | 
|  | 305 | +            } | 
|  | 306 | +            if (rank == 4) { | 
|  | 307 | +                break; | 
|  | 308 | +            } | 
|  | 309 | +        } | 
|  | 310 | + | 
|  | 311 | +        int targetRank = (selectedEntry.searchRankProperty().get()); | 
|  | 312 | +        while (true) { | 
|  | 313 | +            targetRank = Math.floorMod(targetRank + delta, 5); | 
|  | 314 | +            BibEntryTableViewModel entry = firstEntryOfEachRank.get(targetRank); | 
|  | 315 | +            if (entry != null) { | 
|  | 316 | +                getSelectionModel().clearSelection(); | 
|  | 317 | +                getSelectionModel().select(entry); | 
|  | 318 | +                scrollTo(entry); | 
|  | 319 | +                return; | 
|  | 320 | +            } | 
|  | 321 | +        } | 
| 300 | 322 |     } | 
| 301 | 323 | 
 | 
| 302 | 324 |     private void setupKeyBindings(KeyBindingRepository keyBindings) { | 
|  | 
0 commit comments