Skip to content

Commit

Permalink
Fix scroll shortcut to handle rank gaps
Browse files Browse the repository at this point in the history
  • Loading branch information
LoayGhreeb committed Jul 19, 2024
1 parent 26af9f0 commit da05a82
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -247,8 +249,9 @@ private void jumpToSearchKey(TableColumn<BibEntryTableViewModel, ?> sortedColumn
.startsWith(columnSearchTerm))
.findFirst()
.ifPresent(item -> {
this.scrollTo(item);
this.clearAndSelect(item.getEntry());
getSelectionModel().clearSelection();
getSelectionModel().select(item);
scrollTo(item);
});
}

Expand Down Expand Up @@ -289,14 +292,33 @@ public void cut() {
}

private void scrollToRank(int delta) {
int currentRank = getSelectionModel().getSelectedItem().searchRankProperty().get();
getItems().stream()
.filter(item -> item.searchRankProperty().get() == currentRank + delta)
.findFirst()
.ifPresent(item -> {
this.scrollTo(item);
this.clearAndSelect(item.getEntry());
});
BibEntryTableViewModel selectedEntry = getSelectionModel().getSelectedItem();
if (selectedEntry == null) {
return;
}

List<BibEntryTableViewModel> firstEntryOfEachRank = new ArrayList<>(Collections.nCopies(5, null));
for (BibEntryTableViewModel entry : getItems()) {
int rank = entry.searchRankProperty().get();
if (firstEntryOfEachRank.get(rank) == null) {
firstEntryOfEachRank.set(rank, entry);
}
if (rank == 4) {
break;
}
}

int targetRank = (selectedEntry.searchRankProperty().get());
while (true) {
targetRank = Math.floorMod(targetRank + delta, 5);
BibEntryTableViewModel entry = firstEntryOfEachRank.get(targetRank);
if (entry != null) {
getSelectionModel().clearSelection();
getSelectionModel().select(entry);
scrollTo(entry);
return;
}
}
}

private void setupKeyBindings(KeyBindingRepository keyBindings) {
Expand Down

0 comments on commit da05a82

Please sign in to comment.