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

Fix focus and keybinding in search #3182

Merged
merged 2 commits into from
Sep 3, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an issue where a new protected terms list was not available immediately after its addition. [#3161](https://github.com/JabRef/jabref/issues/3161)
- We fixed an issue where an online file link could not be removed from an entry [#3165](https://github.com/JabRef/jabref/issues/3165)
- We fixed an issue where an online file link did not open the browser and created an error [#3165](https://github.com/JabRef/jabref/issues/3165)

- We fixed an issue where the arrow keys in the search bar did not work as expected [#3081](https://github.com/JabRef/jabref/issues/3081)
### Removed


Expand Down
57 changes: 35 additions & 22 deletions src/main/java/org/jabref/gui/search/GlobalSearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,27 +191,7 @@ public void actionPerformed(ActionEvent e) {
container = OS.LINUX ? new CustomJFXPanel() : new JFXPanel();
DefaultTaskExecutor.runInJavaFXThread(() -> {
container.setScene(new Scene(searchField));
container.addKeyListener(new KeyAdapter() {

@Override
public void keyPressed(java.awt.event.KeyEvent e) {
//We need to consume this event here to prevent the propgation of keybinding events back to the JFrame
Optional<KeyBinding> keyBinding = Globals.getKeyPrefs().mapToKeyBinding(e);
if (keyBinding.isPresent()) {
switch (keyBinding.get()) {
case CUT:
case COPY:
case PASTE:
case DELETE_ENTRY:
case SELECT_ALL:
e.consume();
break;
default:
//do nothing
}
}
}
});
container.addKeyListener(new SearchKeyAdapter());

});

Expand Down Expand Up @@ -442,4 +422,37 @@ private void updateOpenCurrentResultsTooltip(boolean globalSearchEnabled) {
}
}

}
private class SearchKeyAdapter extends KeyAdapter {

@Override
public void keyPressed(java.awt.event.KeyEvent e) {
switch (e.getKeyCode()) {
//This "hack" prevents that the focus moves out of the field
case java.awt.event.KeyEvent.VK_RIGHT:
case java.awt.event.KeyEvent.VK_LEFT:
case java.awt.event.KeyEvent.VK_UP:
case java.awt.event.KeyEvent.VK_DOWN:
e.consume();
break;
default:
//do nothing
}

//We need to consume this event here to prevent the propgation of keybinding events back to the JFrame
Optional<KeyBinding> keyBinding = Globals.getKeyPrefs().mapToKeyBinding(e);
if (keyBinding.isPresent()) {
switch (keyBinding.get()) {
case CUT:
case COPY:
case PASTE:
case DELETE_ENTRY:
case SELECT_ALL:
e.consume();
break;
default:
//do nothing
}
}
}
}
}