From 23fd19374a4710d317729a437a12597d8c8969db Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Fri, 1 Sep 2017 13:02:46 +0200 Subject: [PATCH 1/2] Fix focus and keybinding in search --- CHANGELOG.md | 2 +- .../java/org/jabref/gui/search/GlobalSearchBar.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5067fece458..369503e2f2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index 4408fb40bcc..9aa30676a92 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -195,6 +195,18 @@ public void actionPerformed(ActionEvent e) { @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 = Globals.getKeyPrefs().mapToKeyBinding(e); if (keyBinding.isPresent()) { From 681447e5b691c5d044f6553000a050c891ef4109 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Fri, 1 Sep 2017 17:32:47 +0200 Subject: [PATCH 2/2] Move Keyadapter to inenr class --- .../jabref/gui/search/GlobalSearchBar.java | 69 ++++++++++--------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index 9aa30676a92..ceff88ffa20 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -191,39 +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) { - 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 = 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()); }); @@ -454,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 = 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 + } + } + } + } +} \ No newline at end of file