Skip to content

Commit

Permalink
Merge pull request #3760 from mohamean/clear-searchfield-on-esc
Browse files Browse the repository at this point in the history
Pressing ESC while searching clears searchfield and selects first available entry
  • Loading branch information
koppor authored Mar 16, 2018
2 parents 4994d7f + 44b41da commit d99d2d8
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/main/java/org/jabref/gui/search/GlobalSearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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 @@ -136,11 +137,17 @@ public void actionPerformed(ActionEvent e) {
KeyBindingRepository keyBindingRepository = Globals.getKeyPrefs();
addEventFilter(KeyEvent.KEY_PRESSED, event -> {
Optional<KeyBinding> keyBinding = keyBindingRepository.mapToKeyBinding(event);
if (keyBinding.isPresent() && keyBinding.get().equals(KeyBinding.GLOBAL_SEARCH)) {
globalSearch.setSelected(true);
searchPreferences.setGlobalSearch(globalSearch.isSelected());
updateOpenCurrentResultsTooltip(globalSearch.isSelected());
focus();
if (keyBinding.isPresent()) {
if (keyBinding.get().equals(KeyBinding.GLOBAL_SEARCH)) {
globalSearch.setSelected(true);
searchPreferences.setGlobalSearch(globalSearch.isSelected());
updateOpenCurrentResultsTooltip(globalSearch.isSelected());
focus();
} else if (keyBinding.get().equals(KeyBinding.CLEAR_SEARCH)) {
// Clear search and select first entry, if available
clearSearch();
frame.getCurrentBasePanel().getMainTable().getSelectionModel().selectFirst();
}
}
});

Expand Down Expand Up @@ -204,6 +211,7 @@ public void actionPerformed(ActionEvent e) {
searchField,
currentResults
);

this.setAlignment(Pos.CENTER_LEFT);
}

Expand Down

0 comments on commit d99d2d8

Please sign in to comment.