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

Pressing ESC while searching clears searchfield and selects first available entry #3760

Merged
merged 3 commits into from
Mar 16, 2018
Merged
Changes from 2 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
10 changes: 10 additions & 0 deletions src/main/java/org/jabref/gui/search/GlobalSearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import javafx.scene.control.ToolBar;
import javafx.scene.control.Tooltip;
import javafx.scene.control.cell.TextFieldListCell;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.BorderPane;
Expand Down Expand Up @@ -202,6 +203,15 @@ public void actionPerformed(ActionEvent e) {
searchField,
currentResults
);

// Clears search on ESC & select first entry, if available
searchField.setOnKeyPressed((event -> {
if (event.getCode() == KeyCode.ESCAPE) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Clear search" shortcut is customizable. Please use

CLEAR_SEARCH("Clear search", Localization.lang("Clear search"), "ESCAPE", KeyBindingCategory.SEARCH),

to check for the correct key (using a KeyBindingRepository).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just take a look at the setupKeyBindings in the EntryEditor, we use that code in several other classes, too.

MainTable currentTable = frame.getCurrentBasePanel().getMainTable();
clearSearch();
currentTable.getSelectionModel().selectFirst();
}
}));
}

public void performGlobalSearch() {
Expand Down