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

Tab in the last text field in a tab should focus the next tab in the tabs of the entry editor. #11937

Open
koppor opened this issue Oct 12, 2024 · 7 comments · May be fixed by #12087
Open

Tab in the last text field in a tab should focus the next tab in the tabs of the entry editor. #11937

koppor opened this issue Oct 12, 2024 · 7 comments · May be fixed by #12087
Assignees
Labels
📍 Assigned Assigned by assign-issue-action (or manually assigned) entry-editor good first issue An issue intended for project-newcomers. Varies in difficulty.

Comments

@koppor
Copy link
Member

koppor commented Oct 12, 2024

Follow up to #11886

Refs #11785

@juliusalberto
Copy link
Contributor

Hi - I would like to be assigned to this issue please. Thank you!

@ThiloteE ThiloteE added entry-editor good first issue An issue intended for project-newcomers. Varies in difficulty. labels Oct 12, 2024
@github-project-automation github-project-automation bot moved this to Free to take in Good First Issues Oct 12, 2024
@ThiloteE ThiloteE moved this from Free to take to Assigned in Good First Issues Oct 12, 2024
@koppor koppor added the 📍 Assigned Assigned by assign-issue-action (or manually assigned) label Oct 16, 2024
@Noah-Martin1
Copy link

Guidance on Completing Issue

Hello,

I am currently working on this issue with @juliusalberto and I'm a bit stuck. Specifically, I need help with the following:

  1. Finding where JabRef handles tab key events:

    • I am not sure which part of the codebase is responsible for handling the tab key navigation within the Entry Editor. Could you provide guidance on where I should look for the relevant logic? (e.g., which file or class deals with tab key handling or keyboard navigation?)
  2. Implementing the tab key behavior:

    • Once I locate the correct file, where would it be best to add the logic that moves focus to the next tab when pressing Tab in the last field of a tab? Should this be handled as part of an existing focus traversal policy, or would I need to implement a custom listener?

Any pointers or advice on these two points would be greatly appreciated!

Thank you for your help.

@koppor
Copy link
Member Author

koppor commented Oct 18, 2024

We do not know. Create a minimal JavaFX application with two tabs and check how it works there. Then port this knowledge to JabRef.

@Noah-Martin1
Copy link

Noah-Martin1 commented Oct 23, 2024

JavaFX Key Handling and Focus Issue

Hello,

After exploring the codebase, I’ve learned how to check if a TextField in a Tab is the last one, and how to shift the focus to the next tab. However, I’ve encountered an issue with how JavaFX handles key events when a TextField is focused.

For example, if I create a listener for a TextField or even the EntryEditor, the listener won't execute while the TextField is in focus, as the TextField consumes the input before it reaches the listener/handler. This issue is currently evident with the setupKeyBindings function, which is intended to initialize shortcuts for navigating the entry editor. Only the "Ctrl + MINUS" key seems to work due to what I think is JavaFX handling key inputs before setupKeyBindings can.

I’ve tried using addEventFilter instead of addEventHandler, but the result is the same. I’ve also explored using JavaFX’s tabIndex and focus priority logic to control the order of focus between tabs and fields. So that pressing "tab" will cycle through all of the specified components in order. However, since the Tab class doesn’t have built-in tabIndex or focusTraversal properties, this has proven to be quite a challenge.

I’m unsure how to proceed or where I should be focusing my efforts. Any suggestions or guidance would be greatly appreciated thankyou.

@koppor
Copy link
Member Author

koppor commented Oct 23, 2024

I’m unsure how to proceed or where I should be focusing my efforts. Any suggestions or guidance would be greatly appreciated thankyou.

  1. Create a minimal JavaFX application showing the issue. Even smaller application than https://github.com/Siedlerchr/javafxreproducer.
  2. Publish the JavaFX application in a repository on GitHub.
  3. Ask question on Stackoverflow.
  4. Post the link to the stackoverflow question here.

Your text did not include a link to org.jabref.gui.fieldeditors.FieldEditorFX#establishBinding. Did you see this method?

    if (keyBindingRepository.matches(e, {key-for-TAB})) {

We have no key binding configuration for tab-to-next field. Which is OK. Just hard-code TAB.

@Noah-Martin1
Copy link

Your text did not include a link to org.jabref.gui.fieldeditors.FieldEditorFX#establishBinding. Did you see this method?

Ah! Good to know. I implemented this feature by setting up a method in FieldEditorFX that moves the TabPane to the next tab if the user presses "Tab" while in the last TextField of the current tab. I created a method in EntryEditor that checks if the current TextField in focus is the last one by comparing its ID with the Tab's last Field's name. Previously, each TextField didn’t have an ID set, so I updated this by setting each ID to the name of its original Field.

Reasons for this approach:

  1. EntryEditor context requirement: We can't directly check if the current Field in focus is the last without EntryEditor context. Because of the way TextFields are created, we can’t directly locate the last TextField of a Tab, but we can easily identify the last Field in a tab. To bridge this gap, I assigned IDs to each TextField based on their original Field names, allowing for comparison.
  2. Adheres to Field creation policy: This approach adapts to changes in the last TextField depending on the active Tab, as all TextFields are initially created as Fields. Because each TextField is linked to a corresponding Field (with its ID matching the field's name), and the last field in a tab can always be identified through the shownFields method, all TextFields can be checked as the last TextField.

Alternative approach: Another way to address this issue could be to modify the focus traversal list, so pressing "Tab" while a TextField is in focus cycles through the fields until reaching the last one, then moves to the next Tab. However, after spending a short while exploring this option it shows its challenges.

If you’re happy with this implementation, I can create a PR for you to review. Thank you!

@Noah-Martin1
Copy link

Hello,
I have created a PR #12087 for review.
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📍 Assigned Assigned by assign-issue-action (or manually assigned) entry-editor good first issue An issue intended for project-newcomers. Varies in difficulty.
Projects
Status: In Progress
4 participants