Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for jumping in ordered author list by typing letters #6440

Merged
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We created a new install screen for macOS. [#5759](https://github.com/JabRef/jabref/issues/5759)
- We implemented an option to download fulltext files while importing. [#6381](https://github.com/JabRef/jabref/pull/6381)
- We fixed the bug when strike the delete key in the text field. [#6421](https://github.com/JabRef/jabref/issues/6421)
- We added support for jumping to target entry when typing letter/digit after sorting a column in maintable [#6146](https://github.com/JabRef/jabref/issues/6146)

### Changed

Expand Down
27 changes: 27 additions & 0 deletions src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import javafx.collections.ListChangeListener;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.input.ClipboardContent;
Expand Down Expand Up @@ -62,6 +63,19 @@ public MainTable(MainTableDataModel model, JabRefFrame frame,
MainTablePreferences preferences, ExternalFileTypes externalFileTypes, KeyBindingRepository keyBindingRepository) {
super();

this.setOnKeyTyped(key -> {
if (this.getSortOrder().size() == 0) {
leitianjian marked this conversation as resolved.
Show resolved Hide resolved
return;
}
final char keyChar = key.getCharacter().charAt(0);
final TableColumn<BibEntryTableViewModel, ?> sortedColumn = getSortOrder().get(0);
final int target_row_index = this.getEntryIndexByInput(sortedColumn, keyChar);
if (Character.isLetterOrDigit(keyChar) && target_row_index != -1) {
this.scrollTo(target_row_index);
this.getSelectionModel().clearAndSelect(target_row_index);
}
});

this.model = model;
this.database = Objects.requireNonNull(database);

Expand Down Expand Up @@ -123,6 +137,19 @@ public MainTable(MainTableDataModel model, JabRefFrame frame,
database.getDatabase().registerListener(this);
}

private int getEntryIndexByInput(TableColumn<BibEntryTableViewModel, ?> column, char target_char) {
for (int i = 0; i < this.getItems().size(); ++i) {
Object temp = column.getCellObservableValue(i).getValue();
if (temp == null) {
continue;
}
if (temp.toString().toLowerCase().charAt(0) == target_char) {
return i;
}
}
return -1;
calixtus marked this conversation as resolved.
Show resolved Hide resolved
}

@Subscribe
public void listen(EntriesAddedEvent event) {
DefaultTaskExecutor.runInJavaFXThread(() -> clearAndSelect(event.getFirstEntry()));
Expand Down