Skip to content

Commit 086ced1

Browse files
Add tab key navigation for empty text areas to move to the next field (#12547)
* Add tab key navigation for empty text areas to move to the next field * Add tab key navigation for empty text areas to move to the next field # Conflicts: # src/main/java/org/jabref/gui/fieldeditors/EditorTextArea.java * Fix changlog file and refining the description of the change * Fix description in changlog file * Update changlog file --------- Co-authored-by: Christoph <[email protected]>
1 parent 3d4c5c0 commit 086ced1

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
2929
- For the Citation key generator patterns, we reverted how `[authorsAlpha]` would behave to the original pattern and renamed the LNI-based pattern introduced in V6.0-alpha to `[authorsAlphaLNI]`. [#12499](https://github.com/JabRef/jabref/pull/12499)
3030
- We keep the list of recent files if one files could not be found. [#12517](https://github.com/JabRef/jabref/pull/12517)
3131
- During the import process, the labels indicating individual paragraphs within an abstract returned by PubMed/Medline XML are preserved. [#12527](https://github.com/JabRef/jabref/issues/12527)
32+
- Pressing Tab in empty text fields of the entry editor now moves the focus to the next field instead of inserting a tab character. [#11938](https://github.com/JabRef/jabref/issues/11938)
3233

3334
### Fixed
3435

src/main/java/org/jabref/gui/fieldeditors/EditorTextArea.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
import java.util.ResourceBundle;
77
import java.util.function.Supplier;
88

9+
import javafx.event.EventHandler;
910
import javafx.fxml.Initializable;
11+
import javafx.scene.Node;
1012
import javafx.scene.control.ContextMenu;
1113
import javafx.scene.control.MenuItem;
1214
import javafx.scene.control.TextArea;
15+
import javafx.scene.input.KeyCode;
16+
import javafx.scene.input.KeyEvent;
1317

1418
import org.jabref.gui.ClipBoardManager;
1519
import org.jabref.gui.fieldeditors.contextmenu.EditorContextAction;
@@ -36,6 +40,9 @@ public EditorTextArea(final String text) {
3640
setWrapText(true);
3741

3842
ClipBoardManager.addX11Support(this);
43+
44+
// Add our custom Tab key event handler to traverse focus when empty.
45+
addEventFilter(KeyEvent.KEY_PRESSED, new FieldTraversalEventHandler());
3946
}
4047

4148
@Override
@@ -70,4 +77,25 @@ public void paste() {
7077
super.paste();
7178
pasteActionHandler.run();
7279
}
80+
81+
// Custom event handler for Tab key presses.
82+
private static class FieldTraversalEventHandler implements EventHandler<KeyEvent> {
83+
@Override
84+
public void handle(KeyEvent event) {
85+
if (event.getCode() == KeyCode.TAB && !event.isShiftDown() && !event.isControlDown()) {
86+
event.consume();
87+
88+
// Get the current text area
89+
Node node = (Node) event.getSource();
90+
KeyEvent newEvent = new KeyEvent(node,
91+
event.getTarget(), event.getEventType(),
92+
event.getCharacter(), event.getText(),
93+
event.getCode(), event.isShiftDown(),
94+
true, event.isAltDown(),
95+
event.isMetaDown());
96+
97+
node.fireEvent(newEvent);
98+
}
99+
}
100+
}
73101
}

0 commit comments

Comments
 (0)