Skip to content

Conversation

@AmandaBalderas20
Copy link
Contributor

@AmandaBalderas20 AmandaBalderas20 commented Nov 14, 2025

Closes #14237

I fixed an issue where keyboard shortcuts could not be edited in:
Preferences → Keyboard shortcuts.

The KeyEvent was being consumed by global application shortcuts before reaching
the shortcut editor in the KeyBindingsTab. As a result, pressing keys did not
update the selected shortcut, and changes were not persisted.

This PR adds:

  • A key event filter in KeyBindingsTab to ensure the TreeTableView receives key presses.
  • Logic to forward the event to the ViewModel (setNewBindingForCurrent).
  • Correct persistence of edited shortcuts by syncing the repository into GuiPreferences.
  • An updated JUnit test verifying the binding update behavior.

Steps to test

  1. Open JabRef → Preferences → Keyboard shortcuts.
  2. Select any shortcut entry (e.g., “Close library”).
  3. Press a new key combination (e.g., Ctrl+Shift+L).
  4. Click Save.
  5. Restart JabRef.
  6. Verify that:
    • The new shortcut appears in the list.
    • The shortcut works in the application (e.g., Ctrl+Shift+L closes the library).

Screenshots visible changes are not required since UI remains the same.


Mandatory checks

  • I own the copyright of the code submitted and I license it under the MIT license
  • I manually tested my changes in running JabRef (always required)
  • I added JUnit tests for changes (if applicable)
  • [/] I added screenshots in the PR description (not applicable — UI did not change)
  • I described the change in CHANGELOG.md
  • [/] I checked the user documentation: no updates required since UI workflow remains identical

@github-actions
Copy link
Contributor

Hey @AmandaBalderas20!

Thank you for contributing to JabRef! Your help is truly appreciated ❤️.

We have automatic checks in place, based on which you will soon get automated feedback if any of them are failing. We also use TragBot with custom rules that scans your changes and provides some preliminary comments, before a maintainer takes a look. TragBot is still learning, and may not always be accurate. In the "Files changed" tab, you can go through its comments and just click on "Resolve conversation" if you are sure that it is incorrect, or comment on the conversation if you are doubtful.

Please re-check our contribution guide in case of any other doubts related to our contribution workflow.

@Siedlerchr
Copy link
Member

Thanks a lot for your PR, please check the failing tests in KeyBindingsTabModelTest. Maybe they need to be adapted?

@Siedlerchr Siedlerchr added the status: changes-required Pull requests that are not yet complete label Nov 15, 2025
@AmandaBalderas20
Copy link
Contributor Author

I validated the functionality by running the tests individually and as a group using the following commands:

./gradlew :jabgui:test --tests "org.jabref.gui.preferences.keybindings.KeyBindingViewModelTest"

./gradlew :jabgui:test --tests "org.jabref.gui.preferences.keybindings.KeyBindingViewModelTest.resetToDefault"

./gradlew :jabgui:test --tests "org.jabref.gui.preferences.keybindings.KeyBindingViewModelTest.verifyStoreSettingsWritesChanges"
Screenshot 2025-11-17 at 11 56 29 a m

All tests executed successfully. I am not sure if there are other test cases or validation steps that I should do for this area, but everything appears correct.

@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Nov 17, 2025

Optional<String> saved = prefsRepo.get(binding);
assertTrue(saved.isPresent());
assertTrue("ctrl+shift+L".equalsIgnoreCase(saved.get()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this an assertEquals? This makes it easer to see the diff when tests fails

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just do assertEquals(Optional.of("...."), saved)

@Siedlerchr
Copy link
Member

Tess work for me on mac as well.

@koppor
Copy link
Member

koppor commented Nov 17, 2025

  • [/] I described the change in CHANGELOG.md (not applicable — minor behavior fix)

No - you fixed an issue. Please add a line - you can ref the issue there #14237

Siedlerchr
Siedlerchr previously approved these changes Nov 17, 2025
@Siedlerchr Siedlerchr enabled auto-merge November 17, 2025 20:39
@Siedlerchr
Copy link
Member

KeyBindingsTabModelTest fails. I cannot verfiy it because there is an assumeFalse(OSX) inside, so the tests do not run on mac

@koppor
Copy link
Member

koppor commented Nov 20, 2025

Locally

> Task :jabgui:test
org.jabref.gui.keyboard.KeyBindingsTabModelTest setSingleKeyBindingToDefault() FAILED

  org.opentest4j.AssertionFailedError: expected: <false> but was: <true>
      at app/org.jabref/org.jabref.gui.keyboard.KeyBindingsTabModelTest.setSingleKeyBindingToDefault(KeyBindingsTabModelTest.java:173)

org.jabref.gui.keyboard.KeyBindingsTabModelTest setAllKeyBindingsToDefault() FAILED

  org.opentest4j.AssertionFailedError: expected: <false> but was: <true>
      at app/org.jabref/org.jabref.gui.keyboard.KeyBindingsTabModelTest.setAllKeyBindingsToDefault(KeyBindingsTabModelTest.java:140)

Not sure how to proceed

  • A: Think why tests could fail and fix the tests/logic
  • B: Disable tests - and document why the test could fail
  • C: Just disable tests

@koppor koppor added the status: awaiting-second-review For non-trivial changes label Nov 20, 2025
@AmandaBalderas20
Copy link
Contributor Author

I reviewed it and I think the failing tests in KeyBindingsTabModelTest expect hasChanged to be false after resetting a key binding.
After fixing #14237, changing a binding and then resetting it still counts as a modification, so the correct final value is true.
I can update those two tests to assert true instead of false to match the new behavior. Is that okay?

@Siedlerchr
Copy link
Member

It would be great if you add this as comment to the test somehow

@AmandaBalderas20
Copy link
Contributor Author

Okay, so I’ll update the tests and add a comment explaining why hasChanged() is now expected to be true after a reset (because of the fix for #14237)

auto-merge was automatically disabled November 20, 2025 21:00

Head branch was pushed to by a user without write access

Comment on lines 89 to 90
assertTrue(saved.isPresent());
assertTrue("ctrl+shift+L".equalsIgnoreCase(saved.get()));
assertEquals(Optional.of("ctrl+shift+L"), saved);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this, too!

@koppor koppor merged commit aae5b96 into JabRef:main Nov 21, 2025
50 of 51 checks passed
@Scroogeee
Copy link

Scroogeee commented Nov 24, 2025

Does not seem to fix the issue on

JabRef 6.0-alpha.194--2025-11-24--5e08c82
Mac OS X 26.1 aarch64
Java 24.0.2
JavaFX 25.0.1+3

New keycombinations are ignored. How are they supposed to be entered?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to change any keyboard shortcut

5 participants