Skip to content

Commit da05a82

Browse files
committed
Fix scroll shortcut to handle rank gaps
1 parent 26af9f0 commit da05a82

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

src/main/java/org/jabref/gui/maintable/MainTable.java

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.io.File;
44
import java.io.IOException;
55
import java.nio.file.Path;
6+
import java.util.ArrayList;
7+
import java.util.Collections;
68
import java.util.List;
79
import java.util.Objects;
810
import java.util.Optional;
@@ -247,8 +249,9 @@ private void jumpToSearchKey(TableColumn<BibEntryTableViewModel, ?> sortedColumn
247249
.startsWith(columnSearchTerm))
248250
.findFirst()
249251
.ifPresent(item -> {
250-
this.scrollTo(item);
251-
this.clearAndSelect(item.getEntry());
252+
getSelectionModel().clearSelection();
253+
getSelectionModel().select(item);
254+
scrollTo(item);
252255
});
253256
}
254257

@@ -289,14 +292,33 @@ public void cut() {
289292
}
290293

291294
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+
}
300322
}
301323

302324
private void setupKeyBindings(KeyBindingRepository keyBindings) {

0 commit comments

Comments
 (0)